]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
tests: commandtest: Make 'test4' checking daemonization more reliable
authorPeter Krempa <pkrempa@redhat.com>
Tue, 21 Jul 2020 10:32:10 +0000 (12:32 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 27 Jul 2020 13:44:38 +0000 (15:44 +0200)
The 'commandhelper' checks effectively whether the parent process is
still around to report whether it was daemonized or not.

This creates a unlikely race condition in cases when we do actually
daemonize the process as the intermediate process used for the
daemonization might not have terminated yet which would report wrong
result leading to test failure.

For now there's just 'test4' which actually daemonizes the process.

Add an argument '--check-daemonize' which asks for retries of the
daemonization check in cases where we expect that the commandhelper is
going to be daemonized and use it in 'test4' to make the test more
reliable.

I've observed the test failure sporadically when my box is under load
e.g. while building two trees at once.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
tests/commanddata/test4.log
tests/commandhelper.c
tests/commandtest.c

index 24a37a7e9663c1f016db07ce8b21d0e0a951c3de..4fd40cc4747c5778c2572bdbe81f1ca0de1cc156 100644 (file)
@@ -1,3 +1,4 @@
+ARG:--check-daemonize
 ENV:DISPLAY=:0.0
 ENV:HOME=/home/test
 ENV:HOSTNAME=test
index 4266e11902ffcff127629477eff2b4a403cdb3cd..b366483771bcebcc98447bef4fe6aeeb6690d4aa 100644 (file)
@@ -72,6 +72,8 @@ int main(int argc, char **argv) {
     char *buffers[3] = {NULL, NULL, NULL};
     size_t buflen[3] = {0, 0, 0};
     char c;
+    bool daemonize_check = false;
+    size_t daemonize_retries = 3;
 
     if (!log)
         return ret;
@@ -83,6 +85,8 @@ int main(int argc, char **argv) {
             sscanf(argv[i], "%u%c", &readfds[numreadfds++], &c) != 1) {
             printf("Could not parse fd %s\n", argv[i]);
             goto cleanup;
+        } else if (STREQ(argv[i], "--check-daemonize")) {
+            daemonize_check = true;
         }
     }
 
@@ -126,7 +130,18 @@ int main(int argc, char **argv) {
             fprintf(log, "FD:%zu\n", i);
     }
 
-    fprintf(log, "DAEMON:%s\n", getpgrp() != getppid() ? "yes" : "no");
+    while (true) {
+        bool daemonized = getpgrp() != getppid();
+
+        if (daemonize_check && !daemonized && daemonize_retries-- > 0) {
+            usleep(100*1000);
+            continue;
+        }
+
+        fprintf(log, "DAEMON:%s\n", daemonized ? "yes" : "no");
+        break;
+    }
+
     if (!(cwd = getcwd(NULL, 0)))
         goto cleanup;
     if (strlen(cwd) > strlen(".../commanddata") &&
index f0e60ee5fe3db0ef8c7648d02c7dc0dc513fbed9..9bef825239c01bc3789a4e93aebf38c15c08b2bd 100644 (file)
@@ -255,7 +255,8 @@ static int test3(const void *unused G_GNUC_UNUSED)
  */
 static int test4(const void *unused G_GNUC_UNUSED)
 {
-    virCommandPtr cmd = virCommandNew(abs_builddir "/commandhelper");
+    virCommandPtr cmd = virCommandNewArgList(abs_builddir "/commandhelper",
+                                             "--check-daemonize", NULL);
     char *pidfile = virPidFileBuildPath(abs_builddir, "commandhelper");
     pid_t pid;
     int ret = -1;