From bd5367ab3d8d43f52c1e8520de05d24a6cf01d73 Mon Sep 17 00:00:00 2001 From: sven Date: Thu, 1 Feb 2024 08:47:42 +0100 Subject: [PATCH] libguac: nested send instruction test Fix a race condition in the test. The server is not waiting for the child to finish writing the message and this leads to a failed test if the child code is not running fast enough. Signed-Off-By: Sven Auhagen --- src/libguac/tests/socket/nested_send_instruction.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/libguac/tests/socket/nested_send_instruction.c b/src/libguac/tests/socket/nested_send_instruction.c index 14e876b25..fe94f6e5b 100644 --- a/src/libguac/tests/socket/nested_send_instruction.c +++ b/src/libguac/tests/socket/nested_send_instruction.c @@ -22,6 +22,7 @@ #include #include +#include #include /** @@ -123,6 +124,7 @@ static void read_expected_instructions(int fd) { void test_socket__nested_send_instruction() { int fd[2]; + int return_status; /* Create pipe */ CU_ASSERT_EQUAL_FATAL(pipe(fd), 0); @@ -141,6 +143,9 @@ void test_socket__nested_send_instruction() { exit(0); } + /* Wait for child to finish */ + waitpid(childpid, &return_status, 0); + /* Read and verify the expected instructions within the parent process */ close(write_fd); read_expected_instructions(read_fd);