@@ -582,3 +582,83 @@ func TestScheduleGlobalUnits(t *testing.T) {
582
582
}
583
583
}
584
584
}
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: \n stdout: %s\n stderr: %s\n err: %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: \n stdout: %s\n stderr: %s\n err: %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