]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tests: Check job ordering on execution cycles
authorMichal Koutný <mkoutny@suse.com>
Thu, 6 Jun 2019 21:27:20 +0000 (23:27 +0200)
committerMichal Koutný <xm.koutny@gmail.com>
Wed, 26 Jun 2019 21:16:31 +0000 (23:16 +0200)
The test-engine Test2 tests the cycle detection when units a, b and d
all start at once

    ,-------------------after-----------------,
    v                                         |
    a/start ---after---> d/start ---after---> b/start

Extend the test with Test11 that adds i.service which causes a and d
stop (by unordered Conflicts=) while starting b. Because stops precede
starts, we effectively eliminate the job cycle and all transaction jobs
should be applicable.

    ,-------------------after-----------------,
    v                                         |
    a/stop <---after--- d/stop <---after--- b/start
    .                   .                     ^
    .                   .                     |
     '. . . . . . . . . i/start ---after------'

src/test/test-engine.c
test/i.service [new file with mode: 0644]
test/meson.build

index 701594fe538f45375e0a73520d28d244813f90b1..3624a274e28c5604f6f78bcdb6bdee38d453a6fb 100644 (file)
@@ -9,12 +9,14 @@
 #include "rm-rf.h"
 #include "test-helper.h"
 #include "tests.h"
+#include "service.h"
 
 int main(int argc, char *argv[]) {
         _cleanup_(rm_rf_physical_and_freep) char *runtime_dir = NULL;
         _cleanup_(sd_bus_error_free) sd_bus_error err = SD_BUS_ERROR_NULL;
         _cleanup_(manager_freep) Manager *m = NULL;
-        Unit *a = NULL, *b = NULL, *c = NULL, *d = NULL, *e = NULL, *g = NULL, *h = NULL, *unit_with_multiple_dashes = NULL;
+        Unit *a = NULL, *b = NULL, *c = NULL, *d = NULL, *e = NULL, *g = NULL,
+             *h = NULL, *i = NULL, *unit_with_multiple_dashes = NULL;
         Job *j;
         int r;
 
@@ -94,6 +96,20 @@ int main(int argc, char *argv[]) {
         assert_se(manager_add_job(m, JOB_START, h, JOB_FAIL, NULL, NULL, &j) == 0);
         manager_dump_jobs(m, stdout, "\t");
 
+        printf("Load5:\n");
+        manager_clear_jobs(m);
+        assert_se(manager_load_startable_unit_or_warn(m, "i.service", NULL, &i) >= 0);
+        SERVICE(a)->state = SERVICE_RUNNING;
+        SERVICE(d)->state = SERVICE_RUNNING;
+        manager_dump_units(m, stdout, "\t");
+
+        printf("Test11: (Start/stop job ordering, execution cycle)\n");
+        assert_se(manager_add_job(m, JOB_START, i, JOB_FAIL, NULL, NULL, &j) == 0);
+        assert_se(a->job && a->job->type == JOB_STOP);
+        assert_se(d->job && d->job->type == JOB_STOP);
+        assert_se(b->job && b->job->type == JOB_START);
+        manager_dump_jobs(m, stdout, "\t");
+
         assert_se(!hashmap_get(a->dependencies[UNIT_PROPAGATES_RELOAD_TO], b));
         assert_se(!hashmap_get(b->dependencies[UNIT_RELOAD_PROPAGATED_FROM], a));
         assert_se(!hashmap_get(a->dependencies[UNIT_PROPAGATES_RELOAD_TO], c));
diff --git a/test/i.service b/test/i.service
new file mode 100644 (file)
index 0000000..938ea77
--- /dev/null
@@ -0,0 +1,8 @@
+[Unit]
+Description=I
+Conflicts=a.service d.service
+Wants=b.service
+After=b.service
+
+[Service]
+ExecStart=/bin/true
index 17d0f3cddddeea790c5e14e3f37041a20993459d..a2435380811edbaba9aa6fea28a613160da945a7 100644 (file)
@@ -26,6 +26,7 @@ test_data_files = '''
         hello-after-sleep.target
         hello.service
         hwdb/10-bad.hwdb
+        i.service
         journal-data/journal-1.txt
         journal-data/journal-2.txt
         nomem.slice