@@ -319,34 +319,100 @@ func TestAllocations_Stop(t *testing.T) {
319319	testutil .RequireRoot (t )
320320	testutil .Parallel (t )
321321
322- 	c , s  :=  makeClient (t , nil , func (c  * testutil.TestServerConfig ) {
323- 		c .DevMode  =  true 
322+ 	t .Run ("default" , func (t  * testing.T ) {
323+ 		c , s  :=  makeClient (t , nil , func (c  * testutil.TestServerConfig ) {
324+ 			c .DevMode  =  true 
325+ 		})
326+ 		defer  s .Stop ()
327+ 		a  :=  c .Allocations ()
328+ 
329+ 		// wait for node 
330+ 		_  =  oneNodeFromNodeList (t , c .Nodes ())
331+ 
332+ 		// Create a job and register it 
333+ 		job  :=  testJob ()
334+ 		_ , wm , err  :=  c .Jobs ().Register (job , nil )
335+ 		must .NoError (t , err )
336+ 
337+ 		// List allocations. 
338+ 		stubs , qm , err  :=  a .List (& QueryOptions {WaitIndex : wm .LastIndex })
339+ 		must .NoError (t , err )
340+ 		must .SliceLen (t , 1 , stubs )
341+ 
342+ 		// Stop the first allocation. 
343+ 		resp , err  :=  a .Stop (& Allocation {ID : stubs [0 ].ID }, & QueryOptions {WaitIndex : qm .LastIndex })
344+ 		must .NoError (t , err )
345+ 		test .UUIDv4 (t , resp .EvalID )
346+ 		test .NonZero (t , resp .LastIndex )
347+ 
348+ 		// Stop allocation that doesn't exist. 
349+ 		resp , err  =  a .Stop (& Allocation {ID : "invalid" }, & QueryOptions {WaitIndex : qm .LastIndex })
350+ 		must .Error (t , err )
324351	})
325- 	defer  s .Stop ()
326- 	a  :=  c .Allocations ()
327352
328- 	// wait for node 
329- 	_  =  oneNodeFromNodeList (t , c .Nodes ())
330- 
331- 	// Create a job and register it 
332- 	job  :=  testJob ()
333- 	_ , wm , err  :=  c .Jobs ().Register (job , nil )
334- 	must .NoError (t , err )
353+ 	t .Run ("rescheduled" , func (t  * testing.T ) {
354+ 		c , s  :=  makeClient (t , nil , func (c  * testutil.TestServerConfig ) {
355+ 			c .DevMode  =  true 
356+ 		})
357+ 		defer  s .Stop ()
358+ 		a  :=  c .Allocations ()
359+ 
360+ 		// wait for node 
361+ 		_  =  oneNodeFromNodeList (t , c .Nodes ())
362+ 
363+ 		// Create a job and register it 
364+ 		job  :=  testJob ()
365+ 		_ , wm , err  :=  c .Jobs ().Register (job , nil )
366+ 		must .NoError (t , err )
367+ 
368+ 		// List allocations. 
369+ 		stubs , qm , err  :=  a .List (& QueryOptions {WaitIndex : wm .LastIndex })
370+ 		must .NoError (t , err )
371+ 		must .SliceLen (t , 1 , stubs )
372+ 
373+ 		// Stop the first allocation. 
374+ 		resp , err  :=  a .Stop (& Allocation {ID : stubs [0 ].ID }, & QueryOptions {
375+ 			Params :    map [string ]string {"reschedule" : "true" },
376+ 			WaitIndex : qm .LastIndex ,
377+ 		})
378+ 		must .NoError (t , err )
335379
336- 	// List allocations. 
337- 	stubs ,  qm ,  err   :=   a . List ( & QueryOptions { WaitIndex :  wm . LastIndex } )
338- 	must .NoError (t , err )
339- 	must . SliceLen ( t ,  1 ,  stubs )
380+ 		 alloc ,  _ ,  err   :=   a . Info ( stubs [ 0 ]. ID ,  & QueryOptions { WaitIndex :  resp . LastIndex }) 
381+ 		 must . NoError ( t ,  err )
382+ 		 must .True (t , alloc . DesiredTransition . ShouldReschedule (),  must . Sprint ( "allocation should be marked for rescheduling" ) )
383+ 	} )
340384
341- 	// Stop the first allocation. 
342- 	resp , err  :=  a .Stop (& Allocation {ID : stubs [0 ].ID }, & QueryOptions {WaitIndex : qm .LastIndex })
343- 	must .NoError (t , err )
344- 	test .UUIDv4 (t , resp .EvalID )
345- 	test .NonZero (t , resp .LastIndex )
385+ 	t .Run ("no shutdown delay" , func (t  * testing.T ) {
386+ 		c , s  :=  makeClient (t , nil , func (c  * testutil.TestServerConfig ) {
387+ 			c .DevMode  =  true 
388+ 		})
389+ 		defer  s .Stop ()
390+ 		a  :=  c .Allocations ()
391+ 
392+ 		// wait for node 
393+ 		_  =  oneNodeFromNodeList (t , c .Nodes ())
394+ 
395+ 		// Create a job and register it 
396+ 		job  :=  testJob ()
397+ 		_ , wm , err  :=  c .Jobs ().Register (job , nil )
398+ 		must .NoError (t , err )
399+ 
400+ 		// List allocations. 
401+ 		stubs , qm , err  :=  a .List (& QueryOptions {WaitIndex : wm .LastIndex })
402+ 		must .NoError (t , err )
403+ 		must .SliceLen (t , 1 , stubs )
404+ 
405+ 		// Stop the first allocation. 
406+ 		resp , err  :=  a .Stop (& Allocation {ID : stubs [0 ].ID }, & QueryOptions {
407+ 			Params :    map [string ]string {"no_shutdown_delay" : "true" },
408+ 			WaitIndex : qm .LastIndex ,
409+ 		})
410+ 		must .NoError (t , err )
346411
347- 	// Stop allocation that doesn't exist. 
348- 	resp , err  =  a .Stop (& Allocation {ID : "invalid" }, & QueryOptions {WaitIndex : qm .LastIndex })
349- 	must .Error (t , err )
412+ 		alloc , _ , err  :=  a .Info (stubs [0 ].ID , & QueryOptions {WaitIndex : resp .LastIndex })
413+ 		must .NoError (t , err )
414+ 		must .True (t , alloc .DesiredTransition .ShouldIgnoreShutdownDelay (), must .Sprint ("allocation should be marked for no shutdown delay" ))
415+ 	})
350416}
351417
352418// TestAllocations_ExecErrors ensures errors are properly formatted 
@@ -480,6 +546,38 @@ func TestAllocations_ShouldMigrate(t *testing.T) {
480546	must .False (t , DesiredTransition {Migrate : pointerOf (false )}.ShouldMigrate ())
481547}
482548
549+ func  TestAllocations_ShouldReschedule (t  * testing.T ) {
550+ 	testutil .Parallel (t )
551+ 
552+ 	must .True (t , DesiredTransition {Reschedule : pointerOf (true )}.ShouldReschedule ())
553+ 	must .False (t , DesiredTransition {}.ShouldReschedule ())
554+ 	must .False (t , DesiredTransition {Reschedule : pointerOf (false )}.ShouldReschedule ())
555+ }
556+ 
557+ func  TestAllocations_ShouldForceReschedule (t  * testing.T ) {
558+ 	testutil .Parallel (t )
559+ 
560+ 	must .True (t , DesiredTransition {ForceReschedule : pointerOf (true )}.ShouldForceReschedule ())
561+ 	must .False (t , DesiredTransition {}.ShouldForceReschedule ())
562+ 	must .False (t , DesiredTransition {ForceReschedule : pointerOf (false )}.ShouldForceReschedule ())
563+ }
564+ 
565+ func  TestAllocations_ShouldIgnoreShutdownDelay (t  * testing.T ) {
566+ 	testutil .Parallel (t )
567+ 
568+ 	must .True (t , DesiredTransition {NoShutdownDelay : pointerOf (true )}.ShouldIgnoreShutdownDelay ())
569+ 	must .False (t , DesiredTransition {}.ShouldIgnoreShutdownDelay ())
570+ 	must .False (t , DesiredTransition {NoShutdownDelay : pointerOf (false )}.ShouldIgnoreShutdownDelay ())
571+ }
572+ 
573+ func  TestAllocations_ShouldDisableMigrationPlacement (t  * testing.T ) {
574+ 	testutil .Parallel (t )
575+ 
576+ 	must .True (t , DesiredTransition {MigrateDisablePlacement : pointerOf (true )}.ShouldDisableMigrationPlacement ())
577+ 	must .False (t , DesiredTransition {}.ShouldDisableMigrationPlacement ())
578+ 	must .False (t , DesiredTransition {MigrateDisablePlacement : pointerOf (false )}.ShouldDisableMigrationPlacement ())
579+ }
580+ 
483581func  TestAllocations_Services (t  * testing.T ) {
484582	t .Skip ("needs to be implemented" )
485583	// TODO(jrasell) add tests once registration process is in place. 
0 commit comments