[glib: 1/5] tests: fix protocol test on win32




commit f82f4776c05b85d978862e69875ede481c7f6552
Author: Marc-André Lureau <marcandre lureau redhat com>
Date:   Fri Jan 21 21:41:28 2022 +0400

    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>

 glib/tests/protocol.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
---
diff --git a/glib/tests/protocol.c b/glib/tests/protocol.c
index 27ebd99bec..b03aaf97b9 100644
--- a/glib/tests/protocol.c
+++ b/glib/tests/protocol.c
@@ -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);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]