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

Commit c2e360d

Browse files
author
Dongsu Park
committed
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.
1 parent 3d876bf commit c2e360d

File tree

3 files changed

+98
-0
lines changed

3 files changed

+98
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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+
Global=true
9+
Conflicts=conflict-global.*.service
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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+
Global=true
9+
Conflicts=conflict-global.*.service

functional/scheduling_test.go

+80
Original file line numberDiff line numberDiff line change
@@ -582,3 +582,83 @@ func TestScheduleGlobalUnits(t *testing.T) {
582582
}
583583
}
584584
}
585+
586+
// TestScheduleGlobalConflicts starts 2 global units that conflict with each
587+
// other, and check if only the first one can be found.
588+
func TestScheduleGlobalConflicts(t *testing.T) {
589+
// Create a three-member cluster
590+
cluster, err := platform.NewNspawnCluster("smoke")
591+
if err != nil {
592+
t.Fatal(err)
593+
}
594+
defer cluster.Destroy(t)
595+
members, err := platform.CreateNClusterMembers(cluster, 3)
596+
if err != nil {
597+
t.Fatal(err)
598+
}
599+
m0 := members[0]
600+
machines, err := cluster.WaitForNMachines(m0, 3)
601+
if err != nil {
602+
t.Fatal(err)
603+
}
604+
605+
cfGlobal0 := "fixtures/units/conflict-global.0.service"
606+
cfGlobal1 := "fixtures/units/conflict-global.1.service"
607+
608+
// Launch a global unit
609+
stdout, stderr, err := cluster.Fleetctl(m0, "start", "--no-block", cfGlobal0)
610+
if err != nil {
611+
t.Fatalf("Failed starting units: \nstdout: %s\nstderr: %s\nerr: %v", stdout, stderr, err)
612+
}
613+
614+
// the global unit should show up active on 3 machines
615+
_, err = cluster.WaitForNActiveUnits(m0, 3)
616+
if err != nil {
617+
t.Fatal(err)
618+
}
619+
620+
// Now add another global unit, which actually should not be started.
621+
stdout, stderr, err = cluster.Fleetctl(m0, "start", "--no-block", cfGlobal1)
622+
if err != nil {
623+
t.Fatalf("Failed starting unit: \nstdout: %s\nstderr: %s\nerr: %v", stdout, stderr, err)
624+
}
625+
626+
// Should see only 3 units
627+
states, err := cluster.WaitForNActiveUnits(m0, 3)
628+
if err != nil {
629+
t.Fatal(err)
630+
}
631+
632+
// Each machine should have a single global unit conflict-global.0.service,
633+
// but not conflict-global.1.service.
634+
us0 := states[path.Base(cfGlobal0)]
635+
us1 := states[path.Base(cfGlobal1)]
636+
for _, mach := range machines {
637+
var found bool
638+
for _, state := range us0 {
639+
if state.Machine == mach {
640+
found = true
641+
break
642+
}
643+
}
644+
if !found {
645+
t.Fatalf("Did not find global unit on machine %v", mach)
646+
t.Logf("Found unit states:")
647+
for _, state := range states {
648+
t.Logf("%#v", state)
649+
}
650+
}
651+
652+
found = false
653+
for _, state := range us1 {
654+
if state.Machine == mach {
655+
found = true
656+
break
657+
}
658+
}
659+
if found {
660+
t.Fatalf("Did find global unit %s on machine %v", us1, mach)
661+
t.Logf("Global units were not conflicted as expected.")
662+
}
663+
}
664+
}

0 commit comments

Comments
 (0)