From 45b62c4529ee76f0bb6e948626a7fa6a8024e243 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Anic=CC=81?= Date: Fri, 7 Jun 2024 15:39:56 +0200 Subject: [PATCH] io_uring: don't assume completions order We are posting two submission (zero copy send and receive) and then reading two completions. There is no guarantee that those completions will be in the order of submissions. This test was expecting fist send completion then receive. Fix is allowing them to come other way too. --- lib/std/os/linux/IoUring.zig | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/std/os/linux/IoUring.zig b/lib/std/os/linux/IoUring.zig index e5e76b07fe..78ff34aadf 100644 --- a/lib/std/os/linux/IoUring.zig +++ b/lib/std/os/linux/IoUring.zig @@ -3503,10 +3503,6 @@ test "accept multishot" { } test "accept/connect/send_zc/recv" { - if (true) { - // https://github.com/ziglang/zig/issues/20212 - return error.SkipZigTest; - } try skipKernelLessThan(.{ .major = 6, .minor = 0, .patch = 0 }); var ring = IoUring.init(16, 0) catch |err| switch (err) { @@ -3528,25 +3524,28 @@ test "accept/connect/send_zc/recv" { _ = try ring.recv(0xffffffff, socket_test_harness.server, .{ .buffer = buffer_recv[0..] }, 0); try testing.expectEqual(@as(u32, 2), try ring.submit()); + var cqe_send, const cqe_recv = brk: { + const cqe1 = try ring.copy_cqe(); + const cqe2 = try ring.copy_cqe(); + break :brk if (cqe1.user_data == 0xeeeeeeee) .{ cqe1, cqe2 } else .{ cqe2, cqe1 }; + }; + // First completion of zero-copy send. // IORING_CQE_F_MORE, means that there // will be a second completion event / notification for the // request, with the user_data field set to the same value. // buffer_send must be keep alive until second cqe. - var cqe_send = try ring.copy_cqe(); try testing.expectEqual(linux.io_uring_cqe{ .user_data = 0xeeeeeeee, .res = buffer_send.len, .flags = linux.IORING_CQE_F_MORE, }, cqe_send); - const cqe_recv = try ring.copy_cqe(); try testing.expectEqual(linux.io_uring_cqe{ .user_data = 0xffffffff, .res = buffer_recv.len, .flags = cqe_recv.flags & linux.IORING_CQE_F_SOCK_NONEMPTY, }, cqe_recv); - try testing.expectEqualSlices(u8, buffer_send[0..buffer_recv.len], buffer_recv[0..]); // Second completion of zero-copy send.