From 594057fd996ad8401b815ed974f1236c4edc3e08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Koutn=C3=BD?= Date: Thu, 6 Jun 2019 23:27:20 +0200 Subject: [PATCH] tests: Check trivial loop between two jobs 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 | 12 +++++++++++- test/a-conj.service | 8 ++++++++ test/meson.build | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 test/a-conj.service diff --git a/src/test/test-engine.c b/src/test/test-engine.c index 3624a274e2..9809d408f6 100644 --- a/src/test/test-engine.c +++ b/src/test/test-engine.c @@ -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 index 0000000000..db37ae71d4 --- /dev/null +++ b/test/a-conj.service @@ -0,0 +1,8 @@ +[Unit] +Description=A conjugate +Requires=a.service +After=a.service +Before=a.service + +[Service] +ExecStart=/bin/true diff --git a/test/meson.build b/test/meson.build index a243538081..8c71e72667 100644 --- a/test/meson.build +++ b/test/meson.build @@ -2,6 +2,7 @@ test_data_files = ''' a.service + a-conj.service b.service basic.target c.service