@@ -335,34 +335,98 @@ func TestAllocations_Stop(t *testing.T) {
335335 testutil .RequireRoot (t )
336336 testutil .Parallel (t )
337337
338- c , s := makeClient (t , nil , func (c * testutil.TestServerConfig ) {
339- c .DevMode = true
338+ t .Run ("default" , func (t * testing.T ) {
339+ c , s := makeClient (t , nil , func (c * testutil.TestServerConfig ) {
340+ c .DevMode = true
341+ })
342+ defer s .Stop ()
343+ a := c .Allocations ()
344+
345+ // wait for node
346+ _ = oneNodeFromNodeList (t , c .Nodes ())
347+
348+ // Create a job and register it
349+ job := testJob ()
350+ _ , wm , err := c .Jobs ().Register (job , nil )
351+ must .NoError (t , err )
352+
353+ // List allocations.
354+ stubs , qm , err := a .List (& QueryOptions {WaitIndex : wm .LastIndex })
355+ must .NoError (t , err )
356+ must .SliceLen (t , 1 , stubs )
357+
358+ // Stop the first allocation.
359+ resp , err := a .Stop (& Allocation {ID : stubs [0 ].ID }, & QueryOptions {WaitIndex : qm .LastIndex })
360+ must .NoError (t , err )
361+ test .UUIDv4 (t , resp .EvalID )
362+ test .NonZero (t , resp .LastIndex )
363+
364+ // Stop allocation that doesn't exist.
365+ resp , err = a .Stop (& Allocation {ID : "invalid" }, & QueryOptions {WaitIndex : qm .LastIndex })
366+ must .Error (t , err )
340367 })
341- defer s .Stop ()
342- a := c .Allocations ()
343368
344- // wait for node
345- _ = oneNodeFromNodeList (t , c .Nodes ())
346-
347- // Create a job and register it
348- job := testJob ()
349- _ , wm , err := c .Jobs ().Register (job , nil )
350- must .NoError (t , err )
351-
352- // List allocations.
353- stubs , qm , err := a .List (& QueryOptions {WaitIndex : wm .LastIndex })
354- must .NoError (t , err )
355- must .SliceLen (t , 1 , stubs )
356-
357- // Stop the first allocation.
358- resp , err := a .Stop (& Allocation {ID : stubs [0 ].ID }, & QueryOptions {WaitIndex : qm .LastIndex })
359- must .NoError (t , err )
360- test .UUIDv4 (t , resp .EvalID )
361- test .NonZero (t , resp .LastIndex )
369+ t .Run ("rescheduled" , func (t * testing.T ) {
370+ c , s := makeClient (t , nil , func (c * testutil.TestServerConfig ) {
371+ c .DevMode = true
372+ })
373+ defer s .Stop ()
374+ a := c .Allocations ()
375+
376+ // wait for node
377+ _ = oneNodeFromNodeList (t , c .Nodes ())
378+
379+ // Create a job and register it
380+ job := testJob ()
381+ _ , wm , err := c .Jobs ().Register (job , nil )
382+ must .NoError (t , err )
383+
384+ // List allocations.
385+ stubs , qm , err := a .List (& QueryOptions {WaitIndex : wm .LastIndex })
386+ must .NoError (t , err )
387+ must .SliceLen (t , 1 , stubs )
388+
389+ // Stop the first allocation.
390+ resp , err := a .Stop (& Allocation {ID : stubs [0 ].ID }, & QueryOptions {
391+ Params : map [string ]string {"reschedule" : "true" },
392+ WaitIndex : qm .LastIndex ,
393+ })
394+ must .NoError (t , err )
395+ alloc , _ , err := a .Info (stubs [0 ].ID , & QueryOptions {WaitIndex : resp .LastIndex })
396+ must .NoError (t , err )
397+ must .True (t , alloc .DesiredTransition .ShouldReschedule (), must .Sprint ("allocation should be marked for rescheduling" ))
398+ })
362399
363- // Stop allocation that doesn't exist.
364- resp , err = a .Stop (& Allocation {ID : "invalid" }, & QueryOptions {WaitIndex : qm .LastIndex })
365- must .Error (t , err )
400+ t .Run ("no shutdown delay" , func (t * testing.T ) {
401+ c , s := makeClient (t , nil , func (c * testutil.TestServerConfig ) {
402+ c .DevMode = true
403+ })
404+ defer s .Stop ()
405+ a := c .Allocations ()
406+
407+ // wait for node
408+ _ = oneNodeFromNodeList (t , c .Nodes ())
409+
410+ // Create a job and register it
411+ job := testJob ()
412+ _ , wm , err := c .Jobs ().Register (job , nil )
413+ must .NoError (t , err )
414+
415+ // List allocations.
416+ stubs , qm , err := a .List (& QueryOptions {WaitIndex : wm .LastIndex })
417+ must .NoError (t , err )
418+ must .SliceLen (t , 1 , stubs )
419+
420+ // Stop the first allocation.
421+ resp , err := a .Stop (& Allocation {ID : stubs [0 ].ID }, & QueryOptions {
422+ Params : map [string ]string {"no_shutdown_delay" : "true" },
423+ WaitIndex : qm .LastIndex ,
424+ })
425+ must .NoError (t , err )
426+ alloc , _ , err := a .Info (stubs [0 ].ID , & QueryOptions {WaitIndex : resp .LastIndex })
427+ must .NoError (t , err )
428+ must .True (t , alloc .DesiredTransition .ShouldIgnoreShutdownDelay (), must .Sprint ("allocation should be marked for no shutdown delay" ))
429+ })
366430}
367431
368432// TestAllocations_ExecErrors ensures errors are properly formatted
@@ -496,6 +560,38 @@ func TestAllocations_ShouldMigrate(t *testing.T) {
496560 must .False (t , DesiredTransition {Migrate : pointerOf (false )}.ShouldMigrate ())
497561}
498562
563+ func TestAllocations_ShouldReschedule (t * testing.T ) {
564+ testutil .Parallel (t )
565+
566+ must .True (t , DesiredTransition {Reschedule : pointerOf (true )}.ShouldReschedule ())
567+ must .False (t , DesiredTransition {}.ShouldReschedule ())
568+ must .False (t , DesiredTransition {Reschedule : pointerOf (false )}.ShouldReschedule ())
569+ }
570+
571+ func TestAllocations_ShouldForceReschedule (t * testing.T ) {
572+ testutil .Parallel (t )
573+
574+ must .True (t , DesiredTransition {ForceReschedule : pointerOf (true )}.ShouldForceReschedule ())
575+ must .False (t , DesiredTransition {}.ShouldForceReschedule ())
576+ must .False (t , DesiredTransition {ForceReschedule : pointerOf (false )}.ShouldForceReschedule ())
577+ }
578+
579+ func TestAllocations_ShouldIgnoreShutdownDelay (t * testing.T ) {
580+ testutil .Parallel (t )
581+
582+ must .True (t , DesiredTransition {NoShutdownDelay : pointerOf (true )}.ShouldIgnoreShutdownDelay ())
583+ must .False (t , DesiredTransition {}.ShouldIgnoreShutdownDelay ())
584+ must .False (t , DesiredTransition {NoShutdownDelay : pointerOf (false )}.ShouldIgnoreShutdownDelay ())
585+ }
586+
587+ func TestAllocations_ShouldDisableMigrationPlacement (t * testing.T ) {
588+ testutil .Parallel (t )
589+
590+ must .True (t , DesiredTransition {MigrateDisablePlacement : pointerOf (true )}.ShouldDisableMigrationPlacement ())
591+ must .False (t , DesiredTransition {}.ShouldDisableMigrationPlacement ())
592+ must .False (t , DesiredTransition {MigrateDisablePlacement : pointerOf (false )}.ShouldDisableMigrationPlacement ())
593+ }
594+
499595func TestAllocations_Services (t * testing.T ) {
500596 t .Skip ("needs to be implemented" )
501597 // TODO(jrasell) add tests once registration process is in place.
0 commit comments