Skip to content

Commit

Permalink
Fix TestCreateServiceSecretFileMode, TestCreateServiceConfigFileMode
Browse files Browse the repository at this point in the history
These tests wer failing frequently:

    === RUN   TestCreateServiceSecretFileMode
        create_test.go:291: assertion failed: 2 (int) != 1 (int)
    --- FAIL: TestCreateServiceSecretFileMode (7.88s)
    === RUN   TestCreateServiceConfigFileMode
        create_test.go:355: assertion failed: 2 (int) != 1 (int)
    --- FAIL: TestCreateServiceConfigFileMode (7.87s)

Which likely is because the client.TaskList() was only filtering by
service, and not by desired state of the tasks. In case the service
failed to start (several retries needed), this would also return
the failed tasks in the result.

This patch changes the tests to use the GetRunningTasks() utility,
which only returns tasks that are expected to be running.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
  • Loading branch information
thaJeztah committed Oct 22, 2021
1 parent bb6fdac commit f674eaa
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions integration/service/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,8 @@ func TestCreateServiceSecretFileMode(t *testing.T) {

poll.WaitOn(t, swarm.RunningTasksCount(client, serviceID, instances), swarm.ServicePoll)

filter := filters.NewArgs()
filter.Add("service", serviceID)
tasks, err := client.TaskList(ctx, types.TaskListOptions{
Filters: filter,
})
assert.NilError(t, err)
assert.Check(t, is.Equal(len(tasks), 1))
tasks := swarm.GetRunningTasks(t, client, serviceID)
assert.Check(t, is.Equal(len(tasks), instances))

body, err := client.ContainerLogs(ctx, tasks[0].Status.ContainerStatus.ContainerID, types.ContainerLogsOptions{
ShowStdout: true,
Expand Down Expand Up @@ -346,13 +341,8 @@ func TestCreateServiceConfigFileMode(t *testing.T) {

poll.WaitOn(t, swarm.RunningTasksCount(client, serviceID, instances))

filter := filters.NewArgs()
filter.Add("service", serviceID)
tasks, err := client.TaskList(ctx, types.TaskListOptions{
Filters: filter,
})
assert.NilError(t, err)
assert.Check(t, is.Equal(len(tasks), 1))
tasks := swarm.GetRunningTasks(t, client, serviceID)
assert.Check(t, is.Equal(len(tasks), instances))

body, err := client.ContainerLogs(ctx, tasks[0].Status.ContainerStatus.ContainerID, types.ContainerLogsOptions{
ShowStdout: true,
Expand Down

0 comments on commit f674eaa

Please sign in to comment.