Improve Policy Test
@@ -361,9 +361,9 @@ def test_live_policy_file_upload(live_mock_server, test_settings, mocker):
test_settings.update({"start_method": "thread"})
def mock_min_size(self, size):
- return 5
+ return 2
- mocker.patch("wandb.filesync.dir_watcher.PolicyLive.RATE_LIMIT_SECONDS", 5)
+ mocker.patch("wandb.filesync.dir_watcher.PolicyLive.RATE_LIMIT_SECONDS", 2)
mocker.patch(
"wandb.filesync.dir_watcher.PolicyLive.min_wait_for_size", mock_min_size
)
@@ -373,32 +373,31 @@ def test_live_policy_file_upload(live_mock_server, test_settings, mocker):
sent = 0
# file created, should be uploaded
with open(fpath, "w") as fp:
- fp.write("a" * 1000)
+ fp.write("a" * 10000)
fp.close()
wandb.save(fpath, policy="live")
# on save file is sent
sent += os.path.getsize(fpath)
- time.sleep(5.1)
+ time.sleep(2.1)
with open(fpath, "a") as fp:
- fp.write("a" * 100000)
+ fp.write("a" * 10000)
fp.close()
- # 5 seconds is longer than set rate limit
+ # 2.1 seconds is longer than set rate limit
sent += os.path.getsize(fpath)
# give watchdog time to register the change
- time.sleep(1.5)
+ time.sleep(1.0)
# file updated within modified time, should not be uploaded
with open(fpath, "a") as fp:
- fp.write("a" * 25000)
+ fp.write("a" * 10000)
fp.close()
- time.sleep(5.1)
-
+ time.sleep(2.0)
# file updated outside of rate limit should be uploaded
with open(fpath, "a") as fp:
- fp.write("a" * 100000)
+ fp.write("a" * 10000)
fp.close()
sent += os.path.getsize(fpath)
time.sleep(2)
server_ctx = live_mock_server.get_ctx()
- print(server_ctx["file_bytes"])
- assert server_ctx["file_bytes"] - sent < 10000
+ print(server_ctx["file_bytes"], sent)
+ assert abs(server_ctx["file_bytes"] - sent) < 15000
