Skip to content

Commit 34bb5f7

Browse files
committed
tests(test_ckpt_for_fsspec): test for cross-device transactions
1 parent 1790d98 commit 34bb5f7

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

tests/tests_pytorch/trainer/connectors/test_checkpoint_connector.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
import errno
1415
import os
1516
from unittest import mock
1617
from unittest.mock import ANY, Mock
@@ -105,7 +106,7 @@ def test_hpc_max_ckpt_version(tmp_path):
105106
)
106107

107108

108-
def test_ckpt_for_fsspec():
109+
def test_ckpt_for_fsspec(tmpdir):
109110
"""Test that the _CheckpointConnector is able to write to fsspec file systems."""
110111
model = BoringModel()
111112
# hardcoding dir since `tmp_path` can be windows path
@@ -118,6 +119,12 @@ def test_ckpt_for_fsspec():
118119
trainer.save_checkpoint("memory://test_ckpt_for_fsspec/hpc_ckpt_3.ckpt")
119120
trainer.save_checkpoint("memory://test_ckpt_for_fsspec/hpc_ckpt_33.ckpt")
120121

122+
with (
123+
mock.patch("os.rename", side_effect=OSError(errno.EXDEV, "Invalid cross-device link")),
124+
mock.patch("os.chmod", side_effect=PermissionError("Operation not permitted")),
125+
):
126+
trainer.save_checkpoint(tmpdir + "/test_ckpt_for_fsspec/hpc_ckpt_18.ckpt")
127+
121128
assert trainer._checkpoint_connector._hpc_resume_path == "memory://test_ckpt_for_fsspec/hpc_ckpt_33.ckpt"
122129
assert (
123130
trainer._checkpoint_connector._CheckpointConnector__max_ckpt_version_in_folder("memory://test_ckpt_for_fsspec")

0 commit comments

Comments
 (0)