Skip to content

Commit

Permalink
test(artifacts): flush writes instead of sleeping to wait on file wri…
Browse files Browse the repository at this point in the history
…tes (#4523)

test(artifacts): flush writes instead of sleeping

For some reason on my machine the calls to  don't work consistently;
this is faster and more reliable as a way to ensure files are written with
sequential c/m/a times.
  • Loading branch information
moredatarequired authored and andrewtruong committed Dec 2, 2022
1 parent edd0d89 commit 58f6cfc
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions tests/unit_tests/test_wandb_artifacts_cache.py
Expand Up @@ -2,7 +2,6 @@
import os
import pathlib
import random
import time
from multiprocessing import Pool

import pytest
Expand Down Expand Up @@ -162,18 +161,22 @@ def test_artifacts_cache_cleanup():
os.makedirs(path_1)
with open(os.path.join(path_1, "aardvark"), "w") as f:
f.truncate(5000)
time.sleep(0.1)
f.flush()
os.fsync(f)

path_2 = os.path.join(cache_root, "ab")
os.makedirs(path_2)
with open(os.path.join(path_2, "absolute"), "w") as f:
f.truncate(2000)
time.sleep(0.1)
f.flush()
os.fsync(f)

path_3 = os.path.join(cache_root, "ac")
os.makedirs(path_3)
with open(os.path.join(path_3, "accelerate"), "w") as f:
f.truncate(1000)
f.flush()
os.fsync(f)

cache = wandb_sdk.wandb_artifacts.ArtifactsCache("cache")
reclaimed_bytes = cache.cleanup(5000)
Expand Down

0 comments on commit 58f6cfc

Please sign in to comment.