From 804cdabc31b38b840eec2b64dc8bdd9a8e660a6f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Michal=20Koutn=C3=BD?= Date: Thu, 6 Jun 2019 23:27:20 +0200 Subject: [PATCH] tests: Check job ordering on execution cycles 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 | 18 +++++++++++++++++- test/i.service | 8 ++++++++ test/meson.build | 1 + 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 test/i.service diff --git a/src/test/test-engine.c b/src/test/test-engine.c index 701594fe538..3624a274e28 100644 --- a/src/test/test-engine.c +++ b/src/test/test-engine.c @@ -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 index 00000000000..938ea77bdf4 --- /dev/null +++ b/test/i.service @@ -0,0 +1,8 @@ +[Unit] +Description=I +Conflicts=a.service d.service +Wants=b.service +After=b.service + +[Service] +ExecStart=/bin/true diff --git a/test/meson.build b/test/meson.build index 17d0f3cdddd..a2435380811 100644 --- a/test/meson.build +++ b/test/meson.build @@ -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 -- 2.47.3