authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-10-28 22:00:55-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-10-29 06:26:05-07:00
loge8e1e2793a2021d37743b33f28c0e9846525068d
treee11b67792d4be2632a180182e4cd5d4303db20c8
parentb1d270d38ed1fc36a5625f9b0f0f110b6dc12ec7

std.Io: make select unit test not depend on cancellation


1 files changed, 10 insertions(+), 3 deletions(-)

lib/std/Io/test.zig+10-3
...@@ -183,10 +183,10 @@ test "select" {...@@ -183,10 +183,10 @@ test "select" {
183 return;183 return;
184 },184 },
185 };185 };
186 defer if (get_a.cancel(io)) |_| @panic("fail") else |err| assert(err == error.Canceled);186 defer if (get_a.cancel(io)) |_| {} else |_| @panic("fail");
187187
188 var get_b = try io.concurrent(Io.Queue(u8).getOne, .{ &queue, io });188 var get_b = try io.concurrent(Io.Queue(u8).getOne, .{ &queue, io });
189 defer if (get_b.cancel(io)) |_| @panic("fail") else |err| assert(err == error.Canceled);189 defer if (get_b.cancel(io)) |_| {} else |_| @panic("fail");
190190
191 var timeout = io.async(Io.sleep, .{ io, .fromMilliseconds(1), .awake });191 var timeout = io.async(Io.sleep, .{ io, .fromMilliseconds(1), .awake });
192 defer timeout.cancel(io) catch {};192 defer timeout.cancel(io) catch {};
...@@ -198,6 +198,13 @@ test "select" {...@@ -198,6 +198,13 @@ test "select" {
198 })) {198 })) {
199 .get_a => return error.TestFailure,199 .get_a => return error.TestFailure,
200 .get_b => return error.TestFailure,200 .get_b => return error.TestFailure,
201 .timeout => {},201 .timeout => {
202 // Unblock the queues to avoid making this unit test depend on
203 // cancellation.
204 queue.putOneUncancelable(io, 1);
205 queue.putOneUncancelable(io, 1);
206 try testing.expectEqual(1, try get_a.await(io));
207 try testing.expectEqual(1, try get_b.await(io));
208 },
202 }209 }
203}210}