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" {...@@ -741,11 +741,6 @@ test "open file with exclusive lock twice, make sure it waits" {
741 return error.SkipZigTest;741 return error.SkipZigTest;
742 }742 }
743743
744 if (std.Target.current.os.tag == .windows) {
745 // https://github.com/ziglang/zig/issues/7010
746 return error.SkipZigTest;
747 }
748
749 const filename = "file_lock_test.txt";744 const filename = "file_lock_test.txt";
750745
751 var tmp = tmpDir(.{});746 var tmp = tmpDir(.{});
...@@ -770,13 +765,17 @@ test "open file with exclusive lock twice, make sure it waits" {...@@ -770,13 +765,17 @@ test "open file with exclusive lock twice, make sure it waits" {
770 defer t.wait();765 defer t.wait();
771766
772 const SLEEP_TIMEOUT_NS = 10 * std.time.ns_per_ms;767 const SLEEP_TIMEOUT_NS = 10 * std.time.ns_per_ms;
773768 // Make sure we've slept enough.
774 std.time.sleep(SLEEP_TIMEOUT_NS);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 }
775 // Check that createFile is still waiting for the lock to be released.774 // Check that createFile is still waiting for the lock to be released.
776 testing.expect(!evt.isSet());775 testing.expect(!evt.isSet());
777 file.close();776 file.close();
778 // Generous timeout to avoid failures on heavily loaded systems.777 // No timeout to avoid failures on heavily loaded systems.
779 try evt.timedWait(SLEEP_TIMEOUT_NS);778 evt.wait();
780}779}
781780
782test "open file with exclusive nonblocking lock twice (absolute paths)" {781test "open file with exclusive nonblocking lock twice (absolute paths)" {