summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiego Pino Garcia <dpino@igalia.com>2021-03-11 07:30:18 +0000
committerPatrick Griffis <tingping@tingping.se>2021-04-13 21:14:37 +0000
commitdf3ba351785668729de8d9d7cef27d9ea2a8f6b1 (patch)
tree84dd702041d4b6719278490157642fa9be2bc3b8
parentb7a78ad4d9287970ce6fca5d95afdd5692dce089 (diff)
downloadlibsoup-autobahn-integration-new.tar.gz
autobahn-test.c: Implement timeout in main loopautobahn-integration-new
-rw-r--r--.gitlab-ci.yml8
-rw-r--r--tests/autobahn/autobahn-test.c60
-rw-r--r--tests/autobahn/meson.build11
3 files changed, 60 insertions, 19 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index f71c6b63..65a64b88 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -19,7 +19,7 @@ fedora-test:
- cp .gitlab-ci/lcovrc ~/.lcovrc
- meson _build -Db_coverage=true -Dauto_features=enabled
- meson compile -C _build
- - meson test --no-suite autobahn -C _build --verbose
+ - meson test --no-suite autobahn-quick --no-suite autobahn -C _build --verbose
- ninja -C _build coverage-html
artifacts:
reports:
@@ -32,11 +32,11 @@ fedora-test:
- "_build/meson-logs/coveragereport"
coverage: '/^\s+lines\.+:\s+([\d.]+\%)\s+/'
-fedora-autobahn:
+fedora-autobahn-quick:
extends: .build
script:
- meson _build -Dauto-features=enabled -Dautobahn=enabled
- - meson test -C _build --suite autobahn --verbose
+ - meson test -C _build --suite autobahn-quick --verbose
artifacts:
paths:
- "_build/meson-logs/autobahn-report"
@@ -61,7 +61,7 @@ fedora-asan:
SOUP_TEST_NO_IPV6: 1
script:
- meson _build -Dauto-features=enabled -Db_sanitize=address -Dintrospection=disabled -Dvapi=disabled
- - meson test --no-suite autobahn -C _build --verbose --timeout-multiplier=10
+ - meson test --no-suite autobahn-quick --no-suite autobahn -C _build --verbose --timeout-multiplier=10
artifacts:
when: on_failure
paths:
diff --git a/tests/autobahn/autobahn-test.c b/tests/autobahn/autobahn-test.c
index e9c6fd88..a6da3cd4 100644
--- a/tests/autobahn/autobahn-test.c
+++ b/tests/autobahn/autobahn-test.c
@@ -24,9 +24,13 @@
#include <libsoup/soup.h>
+#define TEST_QUICK_THRESHOLD 310
+
static char *address = "ws://localhost:9001";
static char *agent = "libsoup";
+static unsigned long int AUTOBAHN_TEST_TIMEOUT = 60;
+
typedef void (*ConnectionFunc) (SoupWebsocketConnection *socket_connection,
gint type,
GBytes *message,
@@ -58,7 +62,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,12 +120,22 @@ 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 time_t threshold = now + AUTOBAHN_TEST_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);
+ break;
+ }
+ }
g_object_unref (message);
g_free (uri);
- g_free (ctx);
+ if (ctx->done)
+ g_free (ctx);
g_main_context_unref (async_context);
}
@@ -228,6 +242,27 @@ done:
return ret;
}
+static gboolean
+should_run_test (int i)
+{
+ return g_test_slow () || i < TEST_QUICK_THRESHOLD;
+}
+
+static
+void prepare_test (SoupSession *session, int i)
+{
+ char *test_path = g_strdup_printf ("/autobahn/%u", i);
+
+ TestBundle *bundle = g_new0 (TestBundle, 1);
+ bundle->session = session;
+ bundle->num_test_case = i;
+ bundle->path = g_strdup_printf ("/runCase?case=%u&agent=%s", i, agent);
+
+ g_test_add_data_func_full (test_path, bundle, test_case, (GDestroyNotify) test_bundle_free);
+
+ g_free (test_path);
+}
+
int main (int argc, char *argv[])
{
int ret = 0;
@@ -247,20 +282,17 @@ int main (int argc, char *argv[])
num_cases = num_case;
}
+ if (getenv ("AUTOBAHN_TEST_TIMEOUT"))
+ AUTOBAHN_TEST_TIMEOUT = atol (getenv ("AUTOBAHN_TEST_TIMEOUT"));
+
session = soup_session_new ();
soup_session_add_feature_by_type (session, SOUP_TYPE_WEBSOCKET_EXTENSION_MANAGER);
for (int i = num_case; i <= num_cases; i++) {
- char *test_path = g_strdup_printf ("/autobahn/%u", i);
-
- TestBundle *bundle = g_new0 (TestBundle, 1);
- bundle->session = session;
- bundle->num_test_case = i;
- bundle->path = g_strdup_printf ("/runCase?case=%u&agent=%s", i, agent);
-
- g_test_add_data_func_full (test_path, bundle, test_case, (GDestroyNotify)test_bundle_free);
-
- g_free (test_path);
+ if (should_run_test (i))
+ prepare_test (session, i);
+ else
+ g_test_skip ("Ran in quick mode");
}
ret = g_test_run ();
diff --git a/tests/autobahn/meson.build b/tests/autobahn/meson.build
index c4598bd4..e78ff4a7 100644
--- a/tests/autobahn/meson.build
+++ b/tests/autobahn/meson.build
@@ -13,9 +13,18 @@ client = executable('autobahn-test', 'autobahn-test.c',
include_directories : include_directories('..'),
)
+test('autobahn-test-quick', client,
+ suite : 'autobahn-quick',
+ env : env,
+ args: ['-m', 'quick'],
+ timeout : 180,
+ protocol : 'tap',
+)
+
test('autobahn-test', client,
suite : 'autobahn',
env : env,
- timeout : 3600,
+ args: ['-m', 'slow'],
+ timeout : 4500,
protocol : 'tap',
)