Commit e8e1e2793a

Andrew Kelley <andrew@ziglang.org>
2025-10-29 06:00:55
std.Io: make select unit test not depend on cancellation
1 parent b1d270d
Changed files (1)
lib
std
lib/std/Io/test.zig
@@ -183,10 +183,10 @@ test "select" {
             return;
         },
     };
-    defer if (get_a.cancel(io)) |_| @panic("fail") else |err| assert(err == error.Canceled);
+    defer if (get_a.cancel(io)) |_| {} else |_| @panic("fail");
 
     var get_b = try io.concurrent(Io.Queue(u8).getOne, .{ &queue, io });
-    defer if (get_b.cancel(io)) |_| @panic("fail") else |err| assert(err == error.Canceled);
+    defer if (get_b.cancel(io)) |_| {} else |_| @panic("fail");
 
     var timeout = io.async(Io.sleep, .{ io, .fromMilliseconds(1), .awake });
     defer timeout.cancel(io) catch {};
@@ -198,6 +198,13 @@ test "select" {
     })) {
         .get_a => return error.TestFailure,
         .get_b => return error.TestFailure,
-        .timeout => {},
+        .timeout => {
+            // Unblock the queues to avoid making this unit test depend on
+            // cancellation.
+            queue.putOneUncancelable(io, 1);
+            queue.putOneUncancelable(io, 1);
+            try testing.expectEqual(1, try get_a.await(io));
+            try testing.expectEqual(1, try get_b.await(io));
+        },
     }
 }