test(artifacts): flush writes instead of sleeping to wait on file writes
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.
@@ -2,7 +2,6 @@ import base64
import os
import pathlib
import random
-import time
from multiprocessing import Pool
import pytest
@@ -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)
