Signed-off-by: Pradip Dhara <pradipd@microsoft.com>
Pradip Dhara authored on 2017/11/07 15:12:03... | ... |
@@ -11,12 +11,11 @@ import ( |
11 | 11 |
"github.com/docker/docker/client" |
12 | 12 |
"github.com/docker/docker/integration-cli/request" |
13 | 13 |
"github.com/gotestyourself/gotestyourself/poll" |
14 |
- "github.com/stretchr/testify/assert" |
|
15 | 14 |
"github.com/stretchr/testify/require" |
16 | 15 |
"golang.org/x/net/context" |
17 | 16 |
) |
18 | 17 |
|
19 |
-func TestCreateWithLBSandbox(t *testing.T) { |
|
18 |
+func TestCreateServiceMultipleTimes(t *testing.T) { |
|
20 | 19 |
defer setupTest(t)() |
21 | 20 |
d := newSwarm(t) |
22 | 21 |
defer d.Stop(t) |
... | ... |
@@ -33,9 +32,8 @@ func TestCreateWithLBSandbox(t *testing.T) { |
33 | 33 |
require.NoError(t, err) |
34 | 34 |
overlayID := netResp.ID |
35 | 35 |
|
36 |
- var instances uint64 = 1 |
|
36 |
+ var instances uint64 = 4 |
|
37 | 37 |
serviceSpec := swarmServiceSpec("TestService", instances) |
38 |
- |
|
39 | 38 |
serviceSpec.TaskTemplate.Networks = append(serviceSpec.TaskTemplate.Networks, swarm.NetworkAttachmentConfig{Target: overlayName}) |
40 | 39 |
|
41 | 40 |
serviceResp, err := client.ServiceCreate(context.Background(), serviceSpec, types.ServiceCreateOptions{ |
... | ... |
@@ -56,14 +54,26 @@ func TestCreateWithLBSandbox(t *testing.T) { |
56 | 56 |
_, _, err = client.ServiceInspectWithRaw(context.Background(), serviceID, types.ServiceInspectOptions{}) |
57 | 57 |
require.NoError(t, err) |
58 | 58 |
|
59 |
- network, err := client.NetworkInspect(context.Background(), overlayID, types.NetworkInspectOptions{}) |
|
60 |
- require.NoError(t, err) |
|
61 |
- assert.Contains(t, network.Containers, overlayName+"-sbox") |
|
62 |
- |
|
63 | 59 |
err = client.ServiceRemove(context.Background(), serviceID) |
64 | 60 |
require.NoError(t, err) |
65 | 61 |
|
66 | 62 |
poll.WaitOn(t, serviceIsRemoved(client, serviceID), pollSettings) |
63 |
+ poll.WaitOn(t, noTasks(client), pollSettings) |
|
64 |
+ |
|
65 |
+ serviceResp, err = client.ServiceCreate(context.Background(), serviceSpec, types.ServiceCreateOptions{ |
|
66 |
+ QueryRegistry: false, |
|
67 |
+ }) |
|
68 |
+ require.NoError(t, err) |
|
69 |
+ |
|
70 |
+ serviceID2 := serviceResp.ID |
|
71 |
+ poll.WaitOn(t, serviceRunningTasksCount(client, serviceID2, instances), pollSettings) |
|
72 |
+ |
|
73 |
+ err = client.ServiceRemove(context.Background(), serviceID2) |
|
74 |
+ require.NoError(t, err) |
|
75 |
+ |
|
76 |
+ poll.WaitOn(t, serviceIsRemoved(client, serviceID2), pollSettings) |
|
77 |
+ poll.WaitOn(t, noTasks(client), pollSettings) |
|
78 |
+ |
|
67 | 79 |
err = client.NetworkRemove(context.Background(), overlayID) |
68 | 80 |
require.NoError(t, err) |
69 | 81 |
|
... | ... |
@@ -112,6 +122,23 @@ func serviceRunningTasksCount(client client.ServiceAPIClient, serviceID string, |
112 | 112 |
} |
113 | 113 |
} |
114 | 114 |
|
115 |
+func noTasks(client client.ServiceAPIClient) func(log poll.LogT) poll.Result { |
|
116 |
+ return func(log poll.LogT) poll.Result { |
|
117 |
+ filter := filters.NewArgs() |
|
118 |
+ tasks, err := client.TaskList(context.Background(), types.TaskListOptions{ |
|
119 |
+ Filters: filter, |
|
120 |
+ }) |
|
121 |
+ switch { |
|
122 |
+ case err != nil: |
|
123 |
+ return poll.Error(err) |
|
124 |
+ case len(tasks) == 0: |
|
125 |
+ return poll.Success() |
|
126 |
+ default: |
|
127 |
+ return poll.Continue("task count at %d waiting for 0", len(tasks)) |
|
128 |
+ } |
|
129 |
+ } |
|
130 |
+} |
|
131 |
+ |
|
115 | 132 |
func serviceIsRemoved(client client.ServiceAPIClient, serviceID string) func(log poll.LogT) poll.Result { |
116 | 133 |
return func(log poll.LogT) poll.Result { |
117 | 134 |
filter := filters.NewArgs() |