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" {...@@ -1758,9 +1758,7 @@ test "open file with exclusive and shared nonblocking lock" {
1758}1758}
17591759
1760test "open file with exclusive lock twice, make sure second lock waits" {1760test "open file with exclusive lock twice, make sure second lock waits" {
1761 if (builtin.single_threaded) return error.SkipZigTest;1761 testWithAllSupportedPathTypes(struct {
1762
1763 try testWithAllSupportedPathTypes(struct {
1764 fn impl(ctx: *TestContext) !void {1762 fn impl(ctx: *TestContext) !void {
1765 const io = ctx.io;1763 const io = ctx.io;
1766 const filename = try ctx.transformPath("file_lock_test.txt");1764 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" {...@@ -1781,8 +1779,8 @@ test "open file with exclusive lock twice, make sure second lock waits" {
1781 var started: Io.Event = .unset;1779 var started: Io.Event = .unset;
1782 var locked: Io.Event = .unset;1780 var locked: Io.Event = .unset;
17831781
1784 const t = try std.Thread.spawn(.{}, S.checkFn, .{ ctx, filename, &started, &locked });1782 var t = try io.concurrent(S.checkFn, .{ ctx, filename, &started, &locked });
1785 defer t.join();1783 defer t.cancel(io) catch {};
17861784
1787 // Wait for the spawned thread to start trying to acquire the exclusive file lock.1785 // Wait for the spawned thread to start trying to acquire the exclusive file lock.
1788 // Then wait a bit to make sure that can't acquire it since we currently hold the file lock.1786 // 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" {...@@ -1795,8 +1793,12 @@ test "open file with exclusive lock twice, make sure second lock waits" {
1795 // Release the file lock which should unlock the thread to lock it and set the locked event.1793 // Release the file lock which should unlock the thread to lock it and set the locked event.
1796 file.close(io);1794 file.close(io);
1797 try locked.wait(io);1795 try locked.wait(io);
1796 try t.await(io);
1798 }1797 }
1799 }.impl);1798 }.impl) catch |err| switch (err) {
1799 error.ConcurrencyUnavailable => return error.SkipZigTest,
1800 else => |e| return e,
1801 };
1800}1802}
18011803
1802test "open file with exclusive nonblocking lock twice (absolute paths)" {1804test "open file with exclusive nonblocking lock twice (absolute paths)" {