Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
functional: new functional test TestScheduleMultipleConflicts
Browse files Browse the repository at this point in the history
To test the new feature of having multiple values in Conflicts,
introduce a functional test TestScheduleMultipleConflicts().
  • Loading branch information
Dongsu Park committed Oct 27, 2016
1 parent 787c683 commit 1213dbb
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 0 deletions.
8 changes: 8 additions & 0 deletions functional/fixtures/units/conflict.multiple.0.service
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions functional/fixtures/units/conflict.multiple.1.service
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions functional/fixtures/units/conflict.multiple.2.service
Original file line number Diff line number Diff line change
@@ -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
68 changes: 68 additions & 0 deletions functional/scheduling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,74 @@ func TestScheduleOneWayConflict(t *testing.T) {

}

// Start 3 services that conflict with one another. Assert that only
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 1 unit, followed by starting another unit
// that replaces the 1st unit. Then it verifies that the 2 units are
// started on different machines.
Expand Down

0 comments on commit 1213dbb

Please sign in to comment.