From 7677aec2faa0844dd35c5d94445f0b9849b717b1 Mon Sep 17 00:00:00 2001 From: George Kiagiadakis Date: Wed, 15 Jan 2014 17:17:57 +0100 Subject: [PATCH] tests: rtprtx::test_rtxsender_packet_retention: fix race condition Now with rtprtxsend pushing rtx buffers from a different thread, this is necessary to ensure that the result of the test is deterministic. This code makes use of GstCheck's global GMutex and GCond that are being used inside GstCheck's sink pad chain() function in order to synchronize with it. --- tests/check/elements/rtprtx.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/tests/check/elements/rtprtx.c b/tests/check/elements/rtprtx.c index c88e2af8dd..a1ddcbfe50 100644 --- a/tests/check/elements/rtprtx.c +++ b/tests/check/elements/rtprtx.c @@ -1256,12 +1256,26 @@ test_rtxsender_packet_retention (gboolean test_with_time) /* retransmit all the previous ones */ for (j = 1; j < i; j++) { - res = gst_pad_push_event (sinkpad, - create_rtx_event (j, ssrc, payload_type)); - fail_unless_equals_int (res, TRUE); + /* synchronize with the chain() function of the "sinkpad" + * to make sure that rtxsend has pushed the rtx buffer out + * before continuing */ + GList *last_out_buffer = g_list_last (buffers); + g_mutex_lock (&check_mutex); + fail_unless_equals_int (gst_pad_push_event (sinkpad, + create_rtx_event (j, ssrc, payload_type)), TRUE); + /* wait for the rtx packet only if we expect the element + * to actually retransmit something */ + if (j >= MAX (i - half_buffers, 1)) { + guint64 end_time = g_get_monotonic_time () + G_TIME_SPAN_SECOND; + do + res = g_cond_wait_until (&check_cond, &check_mutex, end_time); + while (res == TRUE && last_out_buffer == g_list_last (buffers)); + fail_unless_equals_int (res, TRUE); + } + g_mutex_unlock (&check_mutex); } - /* push this one, triggering the retransmit in rtxsend's chain() function */ + /* push this one */ gst_pad_push (srcpad, gst_buffer_ref (buffer)); node = g_list_next (node); }