Skip to content

Commit 61e749e

Browse files
authored
Merge pull request #6226 from CharlieTLe/fix-docker-stop
Wait until container is removed after stopping
2 parents c461a17 + eec4471 commit 61e749e

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

integration/e2e/scenario_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,17 @@ func TestScenario(t *testing.T) {
146146
_, err = bkt.Get(context.Background(), "recipe")
147147
require.Error(t, err)
148148
}
149+
150+
// TestStartStop tests for ensuring that when the container is stopped, it can be started again.
151+
// This is to test that the stop waits for the container to be stopped and cleaned up before returning.
152+
func TestStartStop(t *testing.T) {
153+
s, err := e2e.NewScenario("e2e-scenario-test")
154+
require.NoError(t, err)
155+
156+
m1 := e2edb.NewMinio(9000, bktName)
157+
158+
for i := 0; i < 10; i++ {
159+
require.NoError(t, s.Start(m1))
160+
require.NoError(t, s.Stop(m1))
161+
}
162+
}

integration/e2e/service.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ func (s *ConcreteService) Stop() error {
151151
logger.Log(string(out))
152152
return err
153153
}
154+
155+
s.Wait()
156+
154157
s.usedNetworkName = ""
155158

156159
return nil
@@ -168,15 +171,22 @@ func (s *ConcreteService) Kill() error {
168171
return err
169172
}
170173

171-
// Wait until the container actually stopped. However, this could fail if
172-
// the container already exited, so we just ignore the error.
173-
_, _ = RunCommandAndGetOutput("docker", "wait", s.containerName())
174+
s.Wait()
174175

175176
s.usedNetworkName = ""
176177

177178
return nil
178179
}
179180

181+
// Wait waits until the service is stopped.
182+
func (s *ConcreteService) Wait() {
183+
// Wait until the container actually stopped. However, this could fail if
184+
// the container already exited, so we just ignore the error.
185+
if out, err := RunCommandAndGetOutput("docker", "wait", s.containerName()); err != nil {
186+
logger.Log(string(out))
187+
}
188+
}
189+
180190
// Endpoint returns external (from host perspective) service endpoint (host:port) for given internal port.
181191
// External means that it will be accessible only from host, but not from docker containers.
182192
//

0 commit comments

Comments
 (0)