]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tests: Check trivial loop between two jobs 12461/head
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)
job_compare return value is undefined in case the jobs have a loop
between them, so better make a test to make sure transaction cycle
detection catches it.

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

index 3624a274e28c5604f6f78bcdb6bdee38d453a6fb..9809d408f641457ee2be26cc16a1dd28de422843 100644 (file)
@@ -16,7 +16,7 @@ int main(int argc, char *argv[]) {
         _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, *i = NULL, *unit_with_multiple_dashes = NULL;
+             *h = NULL, *i = NULL, *a_conj = NULL, *unit_with_multiple_dashes = NULL;
         Job *j;
         int r;
 
@@ -110,6 +110,16 @@ int main(int argc, char *argv[]) {
         assert_se(b->job && b->job->type == JOB_START);
         manager_dump_jobs(m, stdout, "\t");
 
+        printf("Load6:\n");
+        manager_clear_jobs(m);
+        assert_se(manager_load_startable_unit_or_warn(m, "a-conj.service", NULL, &a_conj) >= 0);
+        SERVICE(a)->state = SERVICE_DEAD;
+        manager_dump_units(m, stdout, "\t");
+
+        printf("Test12: (Trivial cycle, Unfixable)\n");
+        assert_se(manager_add_job(m, JOB_START, a_conj, JOB_REPLACE, NULL, NULL, &j) == -EDEADLK);
+        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/a-conj.service b/test/a-conj.service
new file mode 100644 (file)
index 0000000..db37ae7
--- /dev/null
@@ -0,0 +1,8 @@
+[Unit]
+Description=A conjugate
+Requires=a.service
+After=a.service
+Before=a.service
+
+[Service]
+ExecStart=/bin/true
index a2435380811edbaba9aa6fea28a613160da945a7..8c71e726678cf420d6a5a11220a429d7d1e266e1 100644 (file)
@@ -2,6 +2,7 @@
 
 test_data_files = '''
         a.service
+        a-conj.service
         b.service
         basic.target
         c.service