authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-12-04 09:34:37+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-12-04 12:24:50-08:00
logac443b941df08bacb5a37e17d1285cb9f973c4f5
tree30ff67226f5fc184afa218454b09c80d8b92879a
parentb390ced356a2150f21f8d15470f927ccc1c9f3ed

std: Restore file locking test on Windows

Make it even more robust wrt timing problems. Closes #7010

1 files changed, 8 insertions(+), 9 deletions(-)

lib/std/fs/test.zig+8-9
......@@ -741,11 +741,6 @@ test "open file with exclusive lock twice, make sure it waits" {
741741 return error.SkipZigTest;
742742 }
743743
744 if (std.Target.current.os.tag == .windows) {
745 // https://github.com/ziglang/zig/issues/7010
746 return error.SkipZigTest;
747 }
748
749744 const filename = "file_lock_test.txt";
750745
751746 var tmp = tmpDir(.{});
......@@ -770,13 +765,17 @@ test "open file with exclusive lock twice, make sure it waits" {
770765 defer t.wait();
771766
772767 const SLEEP_TIMEOUT_NS = 10 * std.time.ns_per_ms;
773
774 std.time.sleep(SLEEP_TIMEOUT_NS);
768 // Make sure we've slept enough.
769 var timer = try std.time.Timer.start();
770 while (true) {
771 std.time.sleep(SLEEP_TIMEOUT_NS);
772 if (timer.read() >= SLEEP_TIMEOUT_NS) break;
773 }
775774 // Check that createFile is still waiting for the lock to be released.
776775 testing.expect(!evt.isSet());
777776 file.close();
778 // Generous timeout to avoid failures on heavily loaded systems.
779 try evt.timedWait(SLEEP_TIMEOUT_NS);
777 // No timeout to avoid failures on heavily loaded systems.
778 evt.wait();
780779}
781780
782781test "open file with exclusive nonblocking lock twice (absolute paths)" {