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

Commit 1213dbb

Browse files
author
Dongsu Park
committed
functional: new functional test TestScheduleMultipleConflicts
To test the new feature of having multiple values in Conflicts, introduce a functional test TestScheduleMultipleConflicts().
1 parent 787c683 commit 1213dbb

File tree

4 files changed

+94
-0
lines changed

4 files changed

+94
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[Unit]
2+
Description=Test Unit
3+
4+
[Service]
5+
ExecStart=/bin/bash -c "while true; do echo Hello, World!; sleep 1; done"
6+
7+
[X-Fleet]
8+
Conflicts=conflict.2.service conflict.1.service conflict.0.service
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[Unit]
2+
Description=Test Unit
3+
4+
[Service]
5+
ExecStart=/bin/bash -c "while true; do echo Hello, World!; sleep 1; done"
6+
7+
[X-Fleet]
8+
Conflicts=conflict.2.service conflict.1.service conflict.0.service
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[Unit]
2+
Description=Test Unit
3+
4+
[Service]
5+
ExecStart=/bin/bash -c "while true; do echo Hello, World!; sleep 1; done"
6+
7+
[X-Fleet]
8+
Conflicts=conflict.2.service
9+
Conflicts=conflict.1.service
10+
Conflicts=conflict.0.service

functional/scheduling_test.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,74 @@ func TestScheduleOneWayConflict(t *testing.T) {
333333

334334
}
335335

336+
// Start 3 services that conflict with one another. Assert that only
337+
func TestScheduleMultipleConflicts(t *testing.T) {
338+
cluster, err := platform.NewNspawnCluster("smoke")
339+
if err != nil {
340+
t.Fatal(err)
341+
}
342+
defer cluster.Destroy(t)
343+
344+
// Start with a simple three-node cluster
345+
members, err := platform.CreateNClusterMembers(cluster, 3)
346+
if err != nil {
347+
t.Fatal(err)
348+
}
349+
m0 := members[0]
350+
machines, err := cluster.WaitForNMachines(m0, 3)
351+
if err != nil {
352+
t.Fatal(err)
353+
}
354+
355+
// Ensure we can SSH into each machine using fleetctl
356+
for _, machine := range machines {
357+
if stdout, stderr, err := cluster.Fleetctl(m0, "--strict-host-key-checking=false", "ssh", machine, "uptime"); err != nil {
358+
t.Errorf("Unable to SSH into fleet machine: \nstdout: %s\nstderr: %s\nerr: %v", stdout, stderr, err)
359+
}
360+
}
361+
362+
for i := 0; i < 3; i++ {
363+
unit := fmt.Sprintf("fixtures/units/conflict.multiple.%d.service", i)
364+
stdout, stderr, err := cluster.Fleetctl(m0, "start", "--no-block", unit)
365+
if err != nil {
366+
t.Errorf("Failed starting unit %s: \nstdout: %s\nstderr: %s\nerr: %v", unit, stdout, stderr, err)
367+
}
368+
}
369+
370+
// All 3 services should be visible immediately and 3 should become
371+
// ACTIVE shortly thereafter
372+
stdout, stderr, err := cluster.Fleetctl(m0, "list-unit-files", "--no-legend")
373+
if err != nil {
374+
t.Fatalf("Failed to run list-unit-files:\nstdout: %s\nstderr: %s\nerr: %v", stdout, stderr, err)
375+
}
376+
units := strings.Split(strings.TrimSpace(stdout), "\n")
377+
if len(units) != 3 {
378+
t.Fatalf("Did not find five units in cluster: \n%s", stdout)
379+
}
380+
active, err := cluster.WaitForNActiveUnits(m0, 3)
381+
if err != nil {
382+
t.Fatal(err)
383+
}
384+
states, err := util.ActiveToSingleStates(active)
385+
if err != nil {
386+
t.Fatal(err)
387+
}
388+
389+
machineSet := make(map[string]bool)
390+
391+
for unit, unitState := range states {
392+
if len(unitState.Machine) == 0 {
393+
t.Errorf("Unit %s is not reporting machine", unit)
394+
}
395+
396+
machineSet[unitState.Machine] = true
397+
}
398+
399+
if len(machineSet) != 3 {
400+
t.Errorf("3 active units not running on 3 unique machines")
401+
}
402+
}
403+
336404
// TestScheduleReplace starts 1 unit, followed by starting another unit
337405
// that replaces the 1st unit. Then it verifies that the 2 units are
338406
// started on different machines.

0 commit comments

Comments
 (0)