authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-03-31 07:49:19-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-04-01 02:54:25-07:00
logbd05d13d5f36eacbda00f01a17bbdbfaba3bf164
treefc89e549a0d4b7bdcedbe14ed36cf78df1898731
parentda78940dd2175b3f0a60f295f9e3a05cd6bf8f79

std: make file locking tests use io not threads

This will allow the tests to also run in single-threaded evented mode.

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

lib/std/fs/test.zig+8-6
......@@ -1758,9 +1758,7 @@ test "open file with exclusive and shared nonblocking lock" {
17581758}
17591759
17601760test "open file with exclusive lock twice, make sure second lock waits" {
1761 if (builtin.single_threaded) return error.SkipZigTest;
1762
1763 try testWithAllSupportedPathTypes(struct {
1761 testWithAllSupportedPathTypes(struct {
17641762 fn impl(ctx: *TestContext) !void {
17651763 const io = ctx.io;
17661764 const filename = try ctx.transformPath("file_lock_test.txt");
......@@ -1781,8 +1779,8 @@ test "open file with exclusive lock twice, make sure second lock waits" {
17811779 var started: Io.Event = .unset;
17821780 var locked: Io.Event = .unset;
17831781
1784 const t = try std.Thread.spawn(.{}, S.checkFn, .{ ctx, filename, &started, &locked });
1785 defer t.join();
1782 var t = try io.concurrent(S.checkFn, .{ ctx, filename, &started, &locked });
1783 defer t.cancel(io) catch {};
17861784
17871785 // Wait for the spawned thread to start trying to acquire the exclusive file lock.
17881786 // Then wait a bit to make sure that can't acquire it since we currently hold the file lock.
......@@ -1795,8 +1793,12 @@ test "open file with exclusive lock twice, make sure second lock waits" {
17951793 // Release the file lock which should unlock the thread to lock it and set the locked event.
17961794 file.close(io);
17971795 try locked.wait(io);
1796 try t.await(io);
17981797 }
1799 }.impl);
1798 }.impl) catch |err| switch (err) {
1799 error.ConcurrencyUnavailable => return error.SkipZigTest,
1800 else => |e| return e,
1801 };
18001802}
18011803
18021804test "open file with exclusive nonblocking lock twice (absolute paths)" {