From e06ce1d660ed827e1787cf018456198b94f656c2 Mon Sep 17 00:00:00 2001 From: Dongsu Park Date: Mon, 7 Nov 2016 12:39:32 +0100 Subject: [PATCH] functional: new functional test TestScheduleMultipleConflicts To test the new feature of having multiple values in Conflicts, introduce a functional test TestScheduleMultipleConflicts(). --- .../units/conflict.multiple.0.service | 8 +++ .../units/conflict.multiple.1.service | 8 +++ .../units/conflict.multiple.2.service | 10 +++ functional/scheduling_test.go | 68 +++++++++++++++++++ 4 files changed, 94 insertions(+) create mode 100644 functional/fixtures/units/conflict.multiple.0.service create mode 100644 functional/fixtures/units/conflict.multiple.1.service create mode 100644 functional/fixtures/units/conflict.multiple.2.service diff --git a/functional/fixtures/units/conflict.multiple.0.service b/functional/fixtures/units/conflict.multiple.0.service new file mode 100644 index 000000000..4b30e8fc6 --- /dev/null +++ b/functional/fixtures/units/conflict.multiple.0.service @@ -0,0 +1,8 @@ +[Unit] +Description=Test Unit + +[Service] +ExecStart=/bin/bash -c "while true; do echo Hello, World!; sleep 1; done" + +[X-Fleet] +Conflicts=conflict.2.service conflict.1.service conflict.0.service diff --git a/functional/fixtures/units/conflict.multiple.1.service b/functional/fixtures/units/conflict.multiple.1.service new file mode 100644 index 000000000..4b30e8fc6 --- /dev/null +++ b/functional/fixtures/units/conflict.multiple.1.service @@ -0,0 +1,8 @@ +[Unit] +Description=Test Unit + +[Service] +ExecStart=/bin/bash -c "while true; do echo Hello, World!; sleep 1; done" + +[X-Fleet] +Conflicts=conflict.2.service conflict.1.service conflict.0.service diff --git a/functional/fixtures/units/conflict.multiple.2.service b/functional/fixtures/units/conflict.multiple.2.service new file mode 100644 index 000000000..5a93342da --- /dev/null +++ b/functional/fixtures/units/conflict.multiple.2.service @@ -0,0 +1,10 @@ +[Unit] +Description=Test Unit + +[Service] +ExecStart=/bin/bash -c "while true; do echo Hello, World!; sleep 1; done" + +[X-Fleet] +Conflicts=conflict.2.service +Conflicts=conflict.1.service +Conflicts=conflict.0.service diff --git a/functional/scheduling_test.go b/functional/scheduling_test.go index d29066484..6771df2ee 100644 --- a/functional/scheduling_test.go +++ b/functional/scheduling_test.go @@ -333,6 +333,74 @@ func TestScheduleOneWayConflict(t *testing.T) { } +// Start 3 services that conflict with one another. +func TestScheduleMultipleConflicts(t *testing.T) { + cluster, err := platform.NewNspawnCluster("smoke") + if err != nil { + t.Fatal(err) + } + defer cluster.Destroy(t) + + // Start with a simple three-node cluster + 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) + } + + // Ensure we can SSH into each machine using fleetctl + for _, machine := range machines { + if stdout, stderr, err := cluster.Fleetctl(m0, "--strict-host-key-checking=false", "ssh", machine, "uptime"); err != nil { + t.Errorf("Unable to SSH into fleet machine: \nstdout: %s\nstderr: %s\nerr: %v", stdout, stderr, err) + } + } + + for i := 0; i < 3; i++ { + unit := fmt.Sprintf("fixtures/units/conflict.multiple.%d.service", i) + stdout, stderr, err := cluster.Fleetctl(m0, "start", "--no-block", unit) + if err != nil { + t.Errorf("Failed starting unit %s: \nstdout: %s\nstderr: %s\nerr: %v", unit, stdout, stderr, err) + } + } + + // All 3 services should be visible immediately and 3 should become + // ACTIVE shortly thereafter + stdout, stderr, err := cluster.Fleetctl(m0, "list-unit-files", "--no-legend") + if err != nil { + t.Fatalf("Failed to run list-unit-files:\nstdout: %s\nstderr: %s\nerr: %v", stdout, stderr, err) + } + units := strings.Split(strings.TrimSpace(stdout), "\n") + if len(units) != 3 { + t.Fatalf("Did not find five units in cluster: \n%s", stdout) + } + active, err := cluster.WaitForNActiveUnits(m0, 3) + if err != nil { + t.Fatal(err) + } + states, err := util.ActiveToSingleStates(active) + if err != nil { + t.Fatal(err) + } + + machineSet := make(map[string]bool) + + for unit, unitState := range states { + if len(unitState.Machine) == 0 { + t.Errorf("Unit %s is not reporting machine", unit) + } + + machineSet[unitState.Machine] = true + } + + if len(machineSet) != 3 { + t.Errorf("3 active units not running on 3 unique machines") + } +} + // TestScheduleReplace starts 3 units, followed by starting another unit // that replaces the 1st unit. Then it verifies that the original unit // got rescheduled on a different machine.