@@ -333,6 +333,74 @@ func TestScheduleOneWayConflict(t *testing.T) {
333
333
334
334
}
335
335
336
+ // Start 3 services that conflict with one another.
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: \n stdout: %s\n stderr: %s\n err: %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: \n stdout: %s\n stderr: %s\n err: %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:\n stdout: %s\n stderr: %s\n err: %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
+
336
404
// TestScheduleReplace starts 3 units, followed by starting another unit
337
405
// that replaces the 1st unit. Then it verifies that the original unit
338
406
// got rescheduled on a different machine.
0 commit comments