summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Adam <jakub.adam@collabora.com>2019-03-05 18:05:56 +0100
committerJakub Adam <jakub.adam@collabora.com>2019-03-05 19:51:12 +0100
commita02f55866c5fbc6eb738dcf26a462ef641d8b915 (patch)
treee5ffe351399a4ac1eb51f8ac27f22aabd593ef24
parent926afef019ca9f297cebbe13479159ac5c087f00 (diff)
downloadlibnice-a02f55866c5fbc6eb738dcf26a462ef641d8b915.tar.gz
test-send-recv: Fix occasional timeouts
While waiting for write thread to finish sending, keep also receiving so that any STUN messages from the peer still get processed.
-rw-r--r--tests/test-io-stream-common.c6
-rw-r--r--tests/test-io-stream-common.h1
-rw-r--r--tests/test-send-recv.c26
3 files changed, 28 insertions, 5 deletions
diff --git a/tests/test-io-stream-common.c b/tests/test-io-stream-common.c
index 5874cee..0f9adec 100644
--- a/tests/test-io-stream-common.c
+++ b/tests/test-io-stream-common.c
@@ -506,7 +506,11 @@ check_for_termination (TestIOStreamThreadData *data, gsize *recv_count,
gpointer tmp;
/* Wait for transmission to complete. */
- while (*send_count < expected_recv_count);
+ while (*send_count < expected_recv_count) {
+ if (data->callbacks->wait_transmission_cb) {
+ data->callbacks->wait_transmission_cb (data->agent);
+ }
+ }
/* Send a close message. */
tmp = g_object_get_data (G_OBJECT (data->agent), "stream-id");
diff --git a/tests/test-io-stream-common.h b/tests/test-io-stream-common.h
index 680a28c..c69b055 100644
--- a/tests/test-io-stream-common.h
+++ b/tests/test-io-stream-common.h
@@ -65,6 +65,7 @@ typedef struct {
void (*new_selected_pair) (NiceAgent *agent, guint stream_id,
guint component_id, gchar *lfoundation, gchar *rfoundation,
TestIOStreamThreadData *data);
+ void (*wait_transmission_cb) (NiceAgent *agent);
} TestIOStreamCallbacks;
struct _TestIOStreamThreadData {
diff --git a/tests/test-send-recv.c b/tests/test-send-recv.c
index b3740dd..6958346 100644
--- a/tests/test-send-recv.c
+++ b/tests/test-send-recv.c
@@ -806,6 +806,24 @@ read_thread_agent_nonblocking_cb (GInputStream *input_stream,
}
static void
+wait_transmission_cb (NiceAgent *agent)
+{
+ guint stream_id;
+ gpointer tmp;
+ guint8 buffer[1024];
+ GInputVector v = { &buffer, sizeof (buffer) };
+ NiceInputMessage message = { &v, 1, NULL, 0};
+
+ tmp = g_object_get_data (G_OBJECT (agent), "stream-id");
+ stream_id = GPOINTER_TO_UINT (tmp);
+
+ /* While waiting for write thread to finish sending, keep also receiving so
+ * that any STUN messages from the peer still get processed. */
+ nice_agent_recv_messages_nonblocking (agent, stream_id, 1, &message, 1, NULL,
+ NULL);
+}
+
+static void
write_thread_agent_nonblocking_cb (GOutputStream *output_stream,
TestIOStreamThreadData *data)
{
@@ -1105,12 +1123,12 @@ test (gboolean reliable, StreamApi stream_api, gsize n_bytes, guint n_messages,
/* Indexed by StreamApi. */
const TestIOStreamCallbacks callbacks[] = {
{ read_thread_agent_cb,
- write_thread_agent_cb, NULL, NULL, }, /* STREAM_AGENT */
+ write_thread_agent_cb, NULL, NULL, wait_transmission_cb }, /* STREAM_AGENT */
{ read_thread_agent_nonblocking_cb, write_thread_agent_nonblocking_cb,
- NULL, NULL, }, /* STREAM_AGENT_NONBLOCKING */
- { read_thread_gio_cb, write_thread_gio_cb, NULL, NULL, }, /* STREAM_GIO */
+ NULL, NULL, wait_transmission_cb }, /* STREAM_AGENT_NONBLOCKING */
+ { read_thread_gio_cb, write_thread_gio_cb, NULL, NULL, NULL}, /* STREAM_GIO */
{ read_thread_gsource_cb, write_thread_gsource_cb,
- NULL, NULL }, /* STREAM_GSOURCE */
+ NULL, NULL, NULL }, /* STREAM_GSOURCE */
};
test_data_init (&l_data, reliable, stream_api, n_bytes, n_messages,