[libsoup] tests: fix some race conditions
- From: Dan Winship <danw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsoup] tests: fix some race conditions
- Date: Wed, 31 Oct 2012 15:11:21 +0000 (UTC)
commit 04a0a7c674fcc8adc28da84eba1b79c4d9acb246
Author: Dan Winship <danw gnome org>
Date: Wed Oct 31 11:08:06 2012 -0400
tests: fix some race conditions
A few tests were written such that they could fail/crash if the machine
was too slow. Fix.
tests/connection-test.c | 13 ++++++++++---
tests/misc-test.c | 3 ++-
2 files changed, 12 insertions(+), 4 deletions(-)
---
diff --git a/tests/connection-test.c b/tests/connection-test.c
index b9dce7f..ef21ec9 100644
--- a/tests/connection-test.c
+++ b/tests/connection-test.c
@@ -541,8 +541,6 @@ do_max_conns_test (void)
soup_test_session_abort_unref (session);
}
-GMainLoop *loop;
-
static void
np_request_started (SoupSession *session, SoupMessage *msg,
SoupSocket *socket, gpointer user_data)
@@ -562,6 +560,13 @@ np_request_unqueued (SoupSession *session, SoupMessage *msg,
debug_printf (1, " socket is still connected\n");
errors++;
}
+}
+
+static void
+np_request_finished (SoupSession *session, SoupMessage *msg,
+ gpointer user_data)
+{
+ GMainLoop *loop = user_data;
g_main_loop_quit (loop);
}
@@ -571,6 +576,7 @@ do_non_persistent_test_for_session (SoupSession *session)
{
SoupMessage *msg;
SoupSocket *socket = NULL;
+ GMainLoop *loop;
loop = g_main_loop_new (NULL, FALSE);
@@ -584,7 +590,8 @@ do_non_persistent_test_for_session (SoupSession *session)
msg = soup_message_new_from_uri ("GET", base_uri);
soup_message_headers_append (msg->request_headers, "Connection", "close");
g_object_ref (msg);
- soup_session_queue_message (session, msg, NULL, NULL);
+ soup_session_queue_message (session, msg,
+ np_request_finished, loop);
g_main_loop_run (loop);
g_main_loop_unref (loop);
diff --git a/tests/misc-test.c b/tests/misc-test.c
index a71d4aa..19e9ba0 100644
--- a/tests/misc-test.c
+++ b/tests/misc-test.c
@@ -928,6 +928,7 @@ cancel_request_thread (gpointer cancellable)
{
g_usleep (100000); /* .1s */
g_cancellable_cancel (cancellable);
+ g_object_unref (cancellable);
return NULL;
}
@@ -951,7 +952,7 @@ do_cancel_while_reading_req_test_for_session (SoupRequester *requester)
} else {
GThread *thread;
- thread = g_thread_new ("cancel_request_thread", cancel_request_thread, cancellable);
+ thread = g_thread_new ("cancel_request_thread", cancel_request_thread, g_object_ref (cancellable));
soup_test_request_send (req, cancellable, &error);
g_thread_unref (thread);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]