webrtc: fix a slightly racy test
authorMatthew Waters <matthew@centricular.com>
Wed, 6 May 2020 05:35:26 +0000 (15:35 +1000)
committerMatthew Waters <matthew@centricular.com>
Wed, 6 May 2020 05:49:58 +0000 (15:49 +1000)
There is no guarantee that the peer data channel has transitioned to
open when we do.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1247>

tests/check/elements/webrtcbin.c

index e43a4ff..eeb733d 100644 (file)
@@ -1629,7 +1629,13 @@ static const gchar *test_string = "GStreamer WebRTC is awesome!";
 static void
 on_message_string (GObject * channel, const gchar * str, struct test_webrtc *t)
 {
-  gchar *expected = g_object_steal_data (channel, "expected");
+  GstWebRTCDataChannelState state;
+  gchar *expected;
+
+  g_object_get (channel, "ready-state", &state, NULL);
+  fail_unless_equals_int (GST_WEBRTC_DATA_CHANNEL_STATE_OPEN, state);
+
+  expected = g_object_steal_data (channel, "expected");
   g_assert_cmpstr (expected, ==, str);
   g_free (expected);
 
@@ -1645,8 +1651,6 @@ have_data_channel_transfer_string (struct test_webrtc *t, GstElement * element,
 
   g_object_get (our, "ready-state", &state, NULL);
   fail_unless_equals_int (GST_WEBRTC_DATA_CHANNEL_STATE_OPEN, state);
-  g_object_get (other, "ready-state", &state, NULL);
-  fail_unless_equals_int (GST_WEBRTC_DATA_CHANNEL_STATE_OPEN, state);
 
   g_object_set_data_full (our, "expected", g_strdup (test_string), g_free);
   g_signal_connect (our, "on-message-string", G_CALLBACK (on_message_string),
@@ -1704,7 +1708,13 @@ GST_END_TEST;
 static void
 on_message_data (GObject * channel, GBytes * data, struct test_webrtc *t)
 {
-  GBytes *expected = g_object_steal_data (channel, "expected");
+  GstWebRTCDataChannelState state;
+  GBytes *expected;
+
+  g_object_get (channel, "ready-state", &state, NULL);
+  fail_unless_equals_int (GST_WEBRTC_DATA_CHANNEL_STATE_OPEN, state);
+
+  expected = g_object_steal_data (channel, "expected");
   g_assert_cmpbytes (data, expected);
   g_bytes_unref (expected);
 
@@ -1721,8 +1731,6 @@ have_data_channel_transfer_data (struct test_webrtc *t, GstElement * element,
 
   g_object_get (our, "ready-state", &state, NULL);
   fail_unless_equals_int (GST_WEBRTC_DATA_CHANNEL_STATE_OPEN, state);
-  g_object_get (other, "ready-state", &state, NULL);
-  fail_unless_equals_int (GST_WEBRTC_DATA_CHANNEL_STATE_OPEN, state);
 
   g_object_set_data_full (our, "expected", g_bytes_ref (data),
       (GDestroyNotify) g_bytes_unref);