[libsoup/autobahn-integration-new: 23/23] autobahn-test.c: Implement timeout in main loop
- From: Diego Pino <dpino src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsoup/autobahn-integration-new: 23/23] autobahn-test.c: Implement timeout in main loop
- Date: Mon, 15 Mar 2021 14:19:19 +0000 (UTC)
commit dca2fa745d83e4447568c5e86cde1baef47f412d
Author: Diego Pino Garcia <dpino igalia com>
Date: Thu Mar 11 07:30:18 2021 +0000
autobahn-test.c: Implement timeout in main loop
tests/autobahn/autobahn-test.c | 21 ++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)
---
diff --git a/tests/autobahn/autobahn-test.c b/tests/autobahn/autobahn-test.c
index e9c6fd88..a51e7698 100644
--- a/tests/autobahn/autobahn-test.c
+++ b/tests/autobahn/autobahn-test.c
@@ -58,7 +58,7 @@ on_message_received (SoupWebsocketConnection *socket_connection,
{
ConnectionContext *ctx = (ConnectionContext *)data;
- g_test_message ("Message recieved");
+ g_test_message ("Message received");
if (ctx && ctx->method)
ctx->method (socket_connection, type, message, ctx->data);
@@ -116,8 +116,23 @@ connect_and_run (SoupSession *session, char *path, ConnectionFunc method, gpoint
g_test_message ("Connecting to %s", uri);
soup_session_websocket_connect_async (session, message, NULL, NULL, G_PRIORITY_DEFAULT, NULL,
on_connect, ctx);
- while (!ctx->done)
- g_main_context_iteration (async_context, TRUE);
+ time_t now = time(NULL);
+ const int timeout = 30;
+ const time_t threshold = now + timeout;
+ while (!ctx->done) {
+ g_main_context_iteration (async_context, TRUE);
+ now = time(NULL);
+ if (now > threshold) {
+ debug_printf (1, "Test timeout: %s\n", uri);
+ g_test_message ("Test timeout: %s\n", uri);
+
+ // FIXME: On a timeout, if ctx is freed no more test are executed.
+ g_object_unref (message);
+ g_free (uri);
+ g_main_context_unref (async_context);
+ return;
+ }
+ }
g_object_unref (message);
g_free (uri);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]