summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <smcv@debian.org>2021-12-27 18:09:35 +0000
committerPatrick Griffis <pgriffis@igalia.com>2022-01-01 19:03:13 +0000
commit50ae331b7aed4b3f7f85cfb53889d58e8ed44d48 (patch)
tree3c2b03c67373a980611b2716c8c462b56681a3a8
parent2bf112c9a21ac2db30ec8cb15601d6da1fd2eacf (diff)
downloadlibsoup-50ae331b7aed4b3f7f85cfb53889d58e8ed44d48.tar.gz
test-utils: Save Apache server root during initialization
By the time we want to use it during teardown, it is no longer safe to call g_test_build_filename(), because some GTest state is discarded at the end of g_test_run() (see glib#2563). As a result, the command that should shut down the server fails, the server continues to run, and its port is unavailable for the next test-case. This should mostly resolve <https://gitlab.gnome.org/GNOME/libsoup/-/issues/175>. Signed-off-by: Simon McVittie <smcv@debian.org>
-rw-r--r--tests/test-utils.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/tests/test-utils.c b/tests/test-utils.c
index 38ff8bc3..c2a59dab 100644
--- a/tests/test-utils.c
+++ b/tests/test-utils.c
@@ -14,6 +14,7 @@
#ifdef HAVE_APACHE
static gboolean apache_running;
+static char *server_root = NULL;
#endif
static SoupLogger *logger;
@@ -164,7 +165,7 @@ static gboolean
apache_cmd (const char *cmd)
{
GPtrArray *argv;
- char *server_root, *cwd, *pid_file;
+ char *cwd, *pid_file;
#ifdef HAVE_APACHE_2_4
char *default_runtime_dir;
#endif
@@ -173,7 +174,10 @@ apache_cmd (const char *cmd)
GString *str;
guint i;
- server_root = soup_test_build_filename_abs (G_TEST_BUILT, "", NULL);
+ if (server_root == NULL) {
+ g_test_message ("Server root not initialized");
+ return FALSE;
+ }
cwd = g_get_current_dir ();
#ifdef HAVE_APACHE_2_4
@@ -216,7 +220,6 @@ apache_cmd (const char *cmd)
if (ok)
ok = (status == 0);
- g_free (server_root);
g_free (cwd);
g_free (pid_file);
#ifdef HAVE_APACHE_2_4
@@ -236,6 +239,8 @@ apache_init (void)
if (g_getenv ("SOUP_TESTS_ALREADY_RUNNING_APACHE"))
return;
+ server_root = soup_test_build_filename_abs (G_TEST_BUILT, "", NULL);
+
if (!apache_cmd ("start")) {
g_printerr ("Could not start apache\n");
exit (1);
@@ -263,6 +268,8 @@ apache_cleanup (void)
while (kill (pid, 0) == 0)
g_usleep (100);
}
+
+ g_clear_pointer (&server_root, g_free);
}
#endif /* HAVE_APACHE */