Skip to content

Commit

Permalink
test: fix flaky flaky udp_mmsg test (libuv#4652)
Browse files Browse the repository at this point in the history
Replace comparison of `alloc_cb_called` with the total bytes
read (`bytes_read`) to validate the test's correctness.

Fixes: libuv#4650
Signed-off-by: Juan José Arboleda <[email protected]>
  • Loading branch information
juanarbol authored Dec 15, 2024
1 parent e8969bf commit 3d78d12
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions test/test-udp-mmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
#define BUFFER_MULTIPLIER 20
#define MAX_DGRAM_SIZE (64 * 1024)
#define NUM_SENDS 40
#define EXPECTED_MMSG_ALLOCS (NUM_SENDS / BUFFER_MULTIPLIER)

static uv_udp_t recver;
static uv_udp_t sender;
static int recv_cb_called;
static int received_datagrams;
static int read_bytes;
static int close_cb_called;
static int alloc_cb_called;

Expand Down Expand Up @@ -74,6 +74,7 @@ static void recv_cb(uv_udp_t* handle,
const struct sockaddr* addr,
unsigned flags) {
ASSERT_GE(nread, 0);
read_bytes += nread;

/* free and return if this is a mmsg free-only callback invocation */
if (flags & UV_UDP_MMSG_FREE) {
Expand Down Expand Up @@ -140,7 +141,7 @@ TEST_IMPL(udp_mmsg) {

/* On platforms that don't support mmsg, each recv gets its own alloc */
if (uv_udp_using_recvmmsg(&recver))
ASSERT_EQ(alloc_cb_called, EXPECTED_MMSG_ALLOCS);
ASSERT_EQ(read_bytes, NUM_SENDS * 4); /* we're sending 4 bytes per datagram */
else
ASSERT_EQ(alloc_cb_called, recv_cb_called);

Expand Down

0 comments on commit 3d78d12

Please sign in to comment.