[libsoup/autobahn-integration-new: 1/2] autobahn-test.c: Implement timeout in main loop




commit c1d1ef32aa3d6f9e3917aa8ee85d9f50bec0fe11
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..ec3841a5 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 = 20;
+        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]