tests: Make iostream test termination more reliable
authorOlivier Crête <olivier.crete@collabora.com>
Thu, 6 Feb 2020 20:21:50 +0000 (15:21 -0500)
committerOlivier Crête <olivier.crete@ocrete.ca>
Thu, 6 Feb 2020 22:03:50 +0000 (22:03 +0000)
tests/test-io-stream-common.c
tests/test-io-stream-common.h

index 5c86850..af64ef3 100644 (file)
@@ -351,7 +351,7 @@ run_io_stream_test (guint deadlock_timeout, gboolean reliable,
   GMainLoop *error_loop;
   GThread *l_main_thread, *r_main_thread;
   GThread *l_write_thread, *l_read_thread, *r_write_thread, *r_read_thread;
-  TestIOStreamThreadData l_data, r_data;
+  TestIOStreamThreadData l_data = { NULL }, r_data = { NULL };
   GMutex mutex;
   GCond cond;
   guint start_count = 6;
@@ -505,6 +505,7 @@ check_for_termination (TestIOStreamThreadData *data, gsize *recv_count,
 {
   guint stream_id;
   gpointer tmp;
+  GError *error = NULL;
 
   /* Wait for transmission to complete. */
   while (*send_count < expected_recv_count) {
@@ -520,34 +521,28 @@ check_for_termination (TestIOStreamThreadData *data, gsize *recv_count,
   /* Can't be certain enough to test for termination on non-reliable streams.
    * There may be packet losses, etc
    */
-  if (data->reliable) {
-    guint8 buf[65536];
-    gsize buf_len;
+  if (data->io_stream) {
     gssize len;
-    GError *error = NULL;
-
-    g_assert_cmpuint (*recv_count, >=, expected_recv_count);
 
-    buf_len = strlen ("Done");
-    memcpy (buf, "Done", buf_len);
-    len = nice_agent_send (data->agent, stream_id, 1, buf_len, (gchar *) buf);
-    g_assert_cmpint (len, ==, buf_len);
+    g_output_stream_close (g_io_stream_get_output_stream (data->io_stream),
+            NULL, &error);
 
-    /* Wait for a done packet. */
-    len = nice_agent_recv (data->agent, stream_id, 1, buf, buf_len, NULL,
-        &error);
     g_assert_no_error (error);
 
-    g_assert_cmpint (len, ==, strlen ("Done"));
-    g_assert_cmpint (memcmp (buf, "Done", strlen ("Done")), ==, 0);
-
-    *recv_count = *recv_count + 1;
+    len = g_input_stream_skip (g_io_stream_get_input_stream (data->io_stream),
+        1024 * 1024, NULL, &error);
+    g_assert_no_error (error);
+    g_assert_cmpint (len, ==, 0);
   }
 
   /* Remove the stream and run away. */
   nice_agent_remove_stream (data->agent, stream_id);
   g_object_set_data (G_OBJECT (data->agent), "stream-id", GUINT_TO_POINTER (0));
 
+  data->done = TRUE;
+  if (data->other->done)
+    g_main_loop_quit (data->error_loop);
+
   /* If both sides have finished, quit the test main loop. */
   if (*recv_count > expected_recv_count &&
       *other_recv_count > expected_recv_count) {
index c69b055..86f5dd0 100644 (file)
@@ -89,6 +89,8 @@ struct _TestIOStreamThreadData {
   /*< private >*/
   const TestIOStreamCallbacks *callbacks;
 
+  gboolean done;
+
   /* Condition signalling for the stream being open/writeable. */
   gboolean stream_open;
   gboolean stream_ready;