From c2e360d5280ea809266b2be53c27e7e7b8247df5 Mon Sep 17 00:00:00 2001 From: Dongsu Park Date: Wed, 27 Apr 2016 11:20:26 +0200 Subject: [PATCH] functional: a new test TestScheduleGlobalConflicts Introduce a new test TestScheduleGlobalConflicts, to cover the case of global units that conflict with each other. Start 2 global units one after another, and check if only the first one can be found. --- .../fixtures/units/conflict-global.0.service | 9 +++ .../fixtures/units/conflict-global.1.service | 9 +++ functional/scheduling_test.go | 80 +++++++++++++++++++ 3 files changed, 98 insertions(+) create mode 100644 functional/fixtures/units/conflict-global.0.service create mode 100644 functional/fixtures/units/conflict-global.1.service diff --git a/functional/fixtures/units/conflict-global.0.service b/functional/fixtures/units/conflict-global.0.service new file mode 100644 index 000000000..d908cd292 --- /dev/null +++ b/functional/fixtures/units/conflict-global.0.service @@ -0,0 +1,9 @@ +[Unit] +Description=Test Unit + +[Service] +ExecStart=/bin/bash -c "while true; do echo Hello, World!; sleep 1; done" + +[X-Fleet] +Global=true +Conflicts=conflict-global.*.service diff --git a/functional/fixtures/units/conflict-global.1.service b/functional/fixtures/units/conflict-global.1.service new file mode 100644 index 000000000..d908cd292 --- /dev/null +++ b/functional/fixtures/units/conflict-global.1.service @@ -0,0 +1,9 @@ +[Unit] +Description=Test Unit + +[Service] +ExecStart=/bin/bash -c "while true; do echo Hello, World!; sleep 1; done" + +[X-Fleet] +Global=true +Conflicts=conflict-global.*.service diff --git a/functional/scheduling_test.go b/functional/scheduling_test.go index 5f71671e4..b4e35d985 100644 --- a/functional/scheduling_test.go +++ b/functional/scheduling_test.go @@ -582,3 +582,83 @@ func TestScheduleGlobalUnits(t *testing.T) { } } } + +// TestScheduleGlobalConflicts starts 2 global units that conflict with each +// other, and check if only the first one can be found. +func TestScheduleGlobalConflicts(t *testing.T) { + // Create a three-member cluster + cluster, err := platform.NewNspawnCluster("smoke") + if err != nil { + t.Fatal(err) + } + defer cluster.Destroy(t) + members, err := platform.CreateNClusterMembers(cluster, 3) + if err != nil { + t.Fatal(err) + } + m0 := members[0] + machines, err := cluster.WaitForNMachines(m0, 3) + if err != nil { + t.Fatal(err) + } + + cfGlobal0 := "fixtures/units/conflict-global.0.service" + cfGlobal1 := "fixtures/units/conflict-global.1.service" + + // Launch a global unit + stdout, stderr, err := cluster.Fleetctl(m0, "start", "--no-block", cfGlobal0) + if err != nil { + t.Fatalf("Failed starting units: \nstdout: %s\nstderr: %s\nerr: %v", stdout, stderr, err) + } + + // the global unit should show up active on 3 machines + _, err = cluster.WaitForNActiveUnits(m0, 3) + if err != nil { + t.Fatal(err) + } + + // Now add another global unit, which actually should not be started. + stdout, stderr, err = cluster.Fleetctl(m0, "start", "--no-block", cfGlobal1) + if err != nil { + t.Fatalf("Failed starting unit: \nstdout: %s\nstderr: %s\nerr: %v", stdout, stderr, err) + } + + // Should see only 3 units + states, err := cluster.WaitForNActiveUnits(m0, 3) + if err != nil { + t.Fatal(err) + } + + // Each machine should have a single global unit conflict-global.0.service, + // but not conflict-global.1.service. + us0 := states[path.Base(cfGlobal0)] + us1 := states[path.Base(cfGlobal1)] + for _, mach := range machines { + var found bool + for _, state := range us0 { + if state.Machine == mach { + found = true + break + } + } + if !found { + t.Fatalf("Did not find global unit on machine %v", mach) + t.Logf("Found unit states:") + for _, state := range states { + t.Logf("%#v", state) + } + } + + found = false + for _, state := range us1 { + if state.Machine == mach { + found = true + break + } + } + if found { + t.Fatalf("Did find global unit %s on machine %v", us1, mach) + t.Logf("Global units were not conflicted as expected.") + } + } +}