From 33e92afd91274e8b63aceccded344a266d401248 Mon Sep 17 00:00:00 2001 From: Edward Hervey Date: Sat, 27 Oct 2018 15:48:13 +0200 Subject: tests: Solidify tcp connection check The previous failure was a timeout which was due to the sending pipeline pushing test buffer *before* the remote client was accepted. We would therefore never get the buffer on the other side. While the client socket would indeed appear as "connected", this doesn't mean that the remote server side did "accept" it (which is where we then add it to the list of remote parties to which data will be sent). The problem isn't with the element implementation, but to the nature of TCP 3-way handshake. In order to make the test reliable, wait for the sink to have accepted the remote client (by checking the number of handles) before sending out test buffers. --- tests/check/pipelines/tcp.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/tests/check/pipelines/tcp.c b/tests/check/pipelines/tcp.c index 8701484d5..1226a5fb1 100644 --- a/tests/check/pipelines/tcp.c +++ b/tests/check/pipelines/tcp.c @@ -205,10 +205,28 @@ GST_END_TEST; GST_START_TEST (test_that_tcpserversink_and_tcpclientsrc_are_symmetrical) { SymmetryTest st = { 0 }; + GstElement *serversink = gst_check_setup_element ("tcpserversink"); + guint timeout = 100; - symmetry_test_setup (&st, gst_check_setup_element ("tcpserversink"), + symmetry_test_setup (&st, serversink, gst_check_setup_element ("tcpclientsrc")); + /* Wait for the client to *actually* be connected before doing the + * test. The socket connection from the client might very well + * succeed, but that doesn't mean the server has accepted it yet. If + * we don't wait for the server to have accepted the connection, we + * would end up dropping the buffer (because no one is "connected") + * and the receiving side would wait forever. */ + while (timeout) { + guint handles; + g_object_get (serversink, "num-handles", &handles, NULL); + if (handles > 0) + break; + /* Wait for 10ms to see if client connected */ + g_usleep (G_USEC_PER_SEC / 100); + timeout--; + } + symmetry_test_assert_passthrough (&st, gst_buffer_new_wrapped (g_strdup ("hello"), 5)); symmetry_test_teardown (&st); -- cgit v1.2.3