@@ -215,7 +215,7 @@ func TestServiceWithPredefinedNetwork(t *testing.T) {
215215 swarm .ServiceWithNetwork (hostName ),
216216 )
217217
218- poll .WaitOn (t , serviceRunningCount (c , serviceID , instances ), swarm .ServicePoll )
218+ poll .WaitOn (t , swarm . RunningTasksCount (c , serviceID , instances ), swarm .ServicePoll )
219219
220220 _ , _ , err := c .ServiceInspectWithRaw (context .Background (), serviceID , types.ServiceInspectOptions {})
221221 assert .NilError (t , err )
@@ -254,7 +254,7 @@ func TestServiceRemoveKeepsIngressNetwork(t *testing.T) {
254254 }),
255255 )
256256
257- poll .WaitOn (t , serviceRunningCount (c , serviceID , instances ), swarm .ServicePoll )
257+ poll .WaitOn (t , swarm . RunningTasksCount (c , serviceID , instances ), swarm .ServicePoll )
258258
259259 ctx := context .Background ()
260260 _ , _ , err := c .ServiceInspectWithRaw (ctx , serviceID , types.ServiceInspectOptions {})
@@ -279,20 +279,6 @@ func TestServiceRemoveKeepsIngressNetwork(t *testing.T) {
279279 assert .Assert (t , ok , "ingress-sbox not present in ingress network" )
280280}
281281
282- func serviceRunningCount (client client.ServiceAPIClient , serviceID string , instances uint64 ) func (log poll.LogT ) poll.Result {
283- return func (log poll.LogT ) poll.Result {
284- services , err := client .ServiceList (context .Background (), types.ServiceListOptions {})
285- if err != nil {
286- return poll .Error (err )
287- }
288-
289- if len (services ) != int (instances ) {
290- return poll .Continue ("Service count at %d waiting for %d" , len (services ), instances )
291- }
292- return poll .Success ()
293- }
294- }
295-
296282func swarmIngressReady (client client.NetworkAPIClient ) func (log poll.LogT ) poll.Result {
297283 return func (log poll.LogT ) poll.Result {
298284 netInfo , err := client .NetworkInspect (context .Background (), ingressNet , types.NetworkInspectOptions {
@@ -333,76 +319,84 @@ func TestServiceWithDataPathPortInit(t *testing.T) {
333319 skip .If (t , testEnv .OSType == "windows" )
334320 skip .If (t , versions .LessThan (testEnv .DaemonAPIVersion (), "1.40" ), "DataPathPort was added in API v1.40" )
335321 defer setupTest (t )()
336- var ops = []func (* daemon.Daemon ){}
337322 var datapathPort uint32 = 7777
338- ops = append (ops , daemon .WithSwarmDataPathPort (datapathPort ))
339- d := swarm .NewSwarm (t , testEnv , ops ... )
340-
323+ d := swarm .NewSwarm (t , testEnv , daemon .WithSwarmDataPathPort (datapathPort ))
341324 c := d .NewClientT (t )
342- defer c .Close ()
343-
325+ ctx := context .Background ()
344326 // Create a overlay network
345327 name := "saanvisthira" + t .Name ()
346- network .CreateNoError (context .Background (), t , c , name ,
328+ overlayID := network .CreateNoError (context .Background (), t , c , name ,
347329 network .WithDriver ("overlay" ))
348330
349331 var instances uint64 = 1
350332 serviceID := swarm .CreateService (t , d ,
351333 swarm .ServiceWithReplicas (instances ),
334+ swarm .ServiceWithName (name ),
352335 swarm .ServiceWithNetwork (name ),
353336 )
354337
355- poll .WaitOn (t , serviceRunningCount (c , serviceID , instances ), swarm .ServicePoll )
338+ poll .WaitOn (t , swarm . RunningTasksCount (c , serviceID , instances ), swarm .ServicePoll )
356339
357340 info := d .Info (t )
358341 assert .Equal (t , info .Swarm .Cluster .DataPathPort , datapathPort )
359- err := c .ServiceRemove (context .Background (), serviceID )
342+ err := c .ServiceRemove (ctx , serviceID )
343+ assert .NilError (t , err )
344+ poll .WaitOn (t , noServices (ctx , c ), swarm .ServicePoll )
345+ poll .WaitOn (t , swarm .NoTasks (ctx , c ), swarm .ServicePoll )
346+ err = c .NetworkRemove (ctx , overlayID )
347+ assert .NilError (t , err )
348+ c .Close ()
349+ err = d .SwarmLeave (t , true )
360350 assert .NilError (t , err )
361- d .SwarmLeave (t , true )
362351 d .Stop (t )
363352
364353 // Clean up , set it back to original one to make sure other tests don't fail
365354 // call without datapath port option.
366- ops = []func (* daemon.Daemon ){}
367- d = swarm .NewSwarm (t , testEnv , ops ... )
368- c = d .NewClientT (t )
369-
355+ d = swarm .NewSwarm (t , testEnv )
356+ nc := d .NewClientT (t )
357+ defer nc .Close ()
370358 // Create a overlay network
371- name = "saanvisthira" + t .Name ()
372- network .CreateNoError (context . Background () , t , c , name ,
359+ name = "not- saanvisthira" + t .Name ()
360+ overlayID = network .CreateNoError (ctx , t , nc , name ,
373361 network .WithDriver ("overlay" ))
374362
375363 serviceID = swarm .CreateService (t , d ,
376364 swarm .ServiceWithReplicas (instances ),
365+ swarm .ServiceWithName (name ),
377366 swarm .ServiceWithNetwork (name ),
378367 )
379368
380- poll .WaitOn (t , serviceRunningCount ( c , serviceID , instances ), swarm .ServicePoll )
369+ poll .WaitOn (t , swarm . RunningTasksCount ( nc , serviceID , instances ), swarm .ServicePoll )
381370
382371 info = d .Info (t )
383372 var defaultDataPathPort uint32 = 4789
384373 assert .Equal (t , info .Swarm .Cluster .DataPathPort , defaultDataPathPort )
385- err = c .ServiceRemove (context .Background (), serviceID )
374+ err = nc .ServiceRemove (ctx , serviceID )
375+ assert .NilError (t , err )
376+ assert .NilError (t , err )
377+ poll .WaitOn (t , noServices (ctx , nc ), swarm .ServicePoll )
378+ poll .WaitOn (t , swarm .NoTasks (ctx , nc ), swarm .ServicePoll )
379+ err = nc .NetworkRemove (ctx , overlayID )
380+ assert .NilError (t , err )
381+ err = d .SwarmLeave (t , true )
386382 assert .NilError (t , err )
387- d .SwarmLeave (t , true )
388383 defer d .Stop (t )
389384}
390385
391386func TestServiceWithDefaultAddressPoolInit (t * testing.T ) {
392387 skip .If (t , testEnv .OSType == "windows" )
393388 defer setupTest (t )()
394- var ops = []func (* daemon.Daemon ){}
395- ipAddr := []string {"20.20.0.0/16" }
396- ops = append (ops , daemon .WithSwarmDefaultAddrPool (ipAddr ))
397- ops = append (ops , daemon .WithSwarmDefaultAddrPoolSubnetSize (24 ))
398- d := swarm .NewSwarm (t , testEnv , ops ... )
389+ d := swarm .NewSwarm (t , testEnv ,
390+ daemon .WithSwarmDefaultAddrPool ([]string {"20.20.0.0/16" }),
391+ daemon .WithSwarmDefaultAddrPoolSubnetSize (24 ))
399392
400393 cli := d .NewClientT (t )
401394 defer cli .Close ()
395+ ctx := context .Background ()
402396
403397 // Create a overlay network
404398 name := "sthira" + t .Name ()
405- overlayID := network .CreateNoError (context . Background () , t , cli , name ,
399+ overlayID := network .CreateNoError (ctx , t , cli , name ,
406400 network .WithDriver ("overlay" ),
407401 network .WithCheckDuplicate (),
408402 )
@@ -415,27 +409,25 @@ func TestServiceWithDefaultAddressPoolInit(t *testing.T) {
415409 swarm .ServiceWithNetwork (name ),
416410 )
417411
418- poll .WaitOn (t , serviceRunningCount (cli , serviceID , instances ), swarm .ServicePoll )
412+ poll .WaitOn (t , swarm . RunningTasksCount (cli , serviceID , instances ), swarm .ServicePoll )
419413
420- _ , _ , err := cli .ServiceInspectWithRaw (context . Background () , serviceID , types.ServiceInspectOptions {})
414+ _ , _ , err := cli .ServiceInspectWithRaw (ctx , serviceID , types.ServiceInspectOptions {})
421415 assert .NilError (t , err )
422416
423- out , err := cli .NetworkInspect (context . Background () , overlayID , types.NetworkInspectOptions {Verbose : true })
417+ out , err := cli .NetworkInspect (ctx , overlayID , types.NetworkInspectOptions {Verbose : true })
424418 assert .NilError (t , err )
425419 t .Logf ("%s: NetworkInspect: %+v" , t .Name (), out )
426420 assert .Assert (t , len (out .IPAM .Config ) > 0 )
427421 assert .Equal (t , out .IPAM .Config [0 ].Subnet , "20.20.0.0/24" )
428422
429- err = cli .ServiceRemove (context .Background (), serviceID )
423+ err = cli .ServiceRemove (ctx , serviceID )
424+ poll .WaitOn (t , noServices (ctx , cli ), swarm .ServicePoll )
425+ poll .WaitOn (t , swarm .NoTasks (ctx , cli ), swarm .ServicePoll )
426+ assert .NilError (t , err )
427+ err = cli .NetworkRemove (ctx , overlayID )
428+ assert .NilError (t , err )
429+ err = d .SwarmLeave (t , true )
430430 assert .NilError (t , err )
431- d .SwarmLeave (t , true )
432- d .Stop (t )
433-
434- // Clean up , set it back to original one to make sure other tests don't fail
435- ipAddr = []string {"10.0.0.0/8" }
436- ops = append (ops , daemon .WithSwarmDefaultAddrPool (ipAddr ))
437- ops = append (ops , daemon .WithSwarmDefaultAddrPoolSubnetSize (24 ))
438- d = swarm .NewSwarm (t , testEnv , ops ... )
439- d .SwarmLeave (t , true )
440431 defer d .Stop (t )
432+
441433}
0 commit comments