tests: fix protocol test on win32

The pipe must be closed, or the child PID watch doesn't get triggered.

We should remove the message callback source on EOF, as EOF during main
loop run will reach a bad assert in the callback.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
This commit is contained in:
Marc-André Lureau 2022-01-21 21:41:28 +04:00 committed by Philip Withnall
parent ccc2a73e86
commit bda6992fb6

View File

@ -100,7 +100,10 @@ test_message_cb1 (GIOChannel * channel,
g_test_log_buffer_push (user_data, read_bytes, buf);
}
g_assert_cmpuint (status, ==, G_IO_STATUS_AGAIN);
if (status == G_IO_STATUS_EOF)
return FALSE;
else
g_assert_cmpuint (status, ==, G_IO_STATUS_AGAIN);
return TRUE;
}
@ -133,7 +136,6 @@ test_message (void)
GMainLoop * loop;
GError * error = NULL;
gulong child_source;
gulong io_source;
GPid pid = 0;
int pipes[2];
int passed = 0;
@ -159,6 +161,7 @@ test_message (void)
g_error ("error spawning the test: %s", error->message);
}
close (pipes[1]);
tlb = g_test_log_buffer_new ();
loop = g_main_loop_new (NULL, FALSE);
@ -181,7 +184,7 @@ test_message (void)
g_assert (g_io_channel_get_encoding (channel) == NULL);
g_assert (!g_io_channel_get_buffered (channel));
io_source = g_io_add_watch (channel, G_IO_IN, test_message_cb1, tlb);
g_io_add_watch (channel, G_IO_IN, test_message_cb1, tlb);
child_source = g_child_watch_add (pid, test_message_cb2, loop);
g_main_loop_run (loop);
@ -191,7 +194,6 @@ test_message (void)
g_test_expect_message ("GLib", G_LOG_LEVEL_CRITICAL, "Source ID*");
g_assert (!g_source_remove (child_source));
g_test_assert_expected_messages ();
g_assert (g_source_remove (io_source));
g_io_channel_unref (channel);
for (msg = g_test_log_buffer_pop (tlb);
@ -264,7 +266,6 @@ test_error (void)
GMainLoop * loop;
GError * error = NULL;
gulong child_source;
gulong io_source;
GPid pid = 0;
int pipes[2];
@ -286,6 +287,7 @@ test_error (void)
g_error ("error spawning the test: %s", error->message);
}
close (pipes[1]);
tlb = g_test_log_buffer_new ();
loop = g_main_loop_new (NULL, FALSE);
@ -299,7 +301,7 @@ test_error (void)
g_io_channel_set_buffered (channel, FALSE);
g_io_channel_set_flags (channel, G_IO_FLAG_NONBLOCK, NULL);
io_source = g_io_add_watch (channel, G_IO_IN, test_message_cb1, tlb);
g_io_add_watch (channel, G_IO_IN, test_message_cb1, tlb);
child_source = g_child_watch_add (pid, test_message_cb2, loop);
g_main_loop_run (loop);
@ -309,7 +311,6 @@ test_error (void)
g_test_expect_message ("GLib", G_LOG_LEVEL_CRITICAL, "Source ID*");
g_assert (!g_source_remove (child_source));
g_test_assert_expected_messages ();
g_assert (g_source_remove (io_source));
g_io_channel_unref (channel);
for (msg = g_test_log_buffer_pop (tlb);