@@ -271,29 +271,12 @@ func TestTemplatedConfig(t *testing.T) {
271271 swarm .ServiceWithName ("svc" ),
272272 )
273273
274- var tasks []swarmtypes.Task
275- getRunningTasks := func (log poll.LogT ) poll.Result {
276- tasks = swarm .GetRunningTasks (t , c , serviceID )
277- if len (tasks ) > 0 {
278- return poll .Success ()
279- }
280- return poll .Continue ("task still waiting" )
281- }
282- poll .WaitOn (t , getRunningTasks , swarm .ServicePoll , poll .WithTimeout (1 * time .Minute ))
283-
284- task := tasks [0 ]
285- getTask := func (log poll.LogT ) poll.Result {
286- if task .NodeID == "" || (task .Status .ContainerStatus == nil || task .Status .ContainerStatus .ContainerID == "" ) {
287- task , _ , _ = c .TaskInspectWithRaw (context .Background (), task .ID )
288- }
289- if task .NodeID != "" && task .Status .ContainerStatus != nil && task .Status .ContainerStatus .ContainerID != "" {
290- return poll .Success ()
291- }
292- return poll .Continue ("task still waiting" )
293- }
294- poll .WaitOn (t , getTask , swarm .ServicePoll , poll .WithTimeout (1 * time .Minute ))
274+ poll .WaitOn (t , swarm .RunningTasksCount (c , serviceID , 1 ), swarm .ServicePoll , poll .WithTimeout (1 * time .Minute ))
275+
276+ tasks := swarm .GetRunningTasks (t , c , serviceID )
277+ assert .Assert (t , len (tasks ) > 0 , "no running tasks found for service %s" , serviceID )
295278
296- attach := swarm .ExecTask (t , d , task , types.ExecConfig {
279+ attach := swarm .ExecTask (t , d , tasks [ 0 ] , types.ExecConfig {
297280 Cmd : []string {"/bin/cat" , "/" + templatedConfigName },
298281 AttachStdout : true ,
299282 AttachStderr : true ,
@@ -304,7 +287,7 @@ func TestTemplatedConfig(t *testing.T) {
304287 "this is a config\n "
305288 assertAttachedStream (t , attach , expect )
306289
307- attach = swarm .ExecTask (t , d , task , types.ExecConfig {
290+ attach = swarm .ExecTask (t , d , tasks [ 0 ] , types.ExecConfig {
308291 Cmd : []string {"mount" },
309292 AttachStdout : true ,
310293 AttachStderr : true ,
0 commit comments