Skip to content

Commit

Permalink
Merge pull request #6226 from CharlieTLe/fix-docker-stop
Browse files Browse the repository at this point in the history
Wait until container is removed after stopping
  • Loading branch information
CharlieTLe authored Sep 26, 2024
2 parents c461a17 + eec4471 commit 61e749e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
14 changes: 14 additions & 0 deletions integration/e2e/scenario_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,17 @@ func TestScenario(t *testing.T) {
_, err = bkt.Get(context.Background(), "recipe")
require.Error(t, err)
}

// TestStartStop tests for ensuring that when the container is stopped, it can be started again.
// This is to test that the stop waits for the container to be stopped and cleaned up before returning.
func TestStartStop(t *testing.T) {
s, err := e2e.NewScenario("e2e-scenario-test")
require.NoError(t, err)

m1 := e2edb.NewMinio(9000, bktName)

for i := 0; i < 10; i++ {
require.NoError(t, s.Start(m1))
require.NoError(t, s.Stop(m1))
}
}
16 changes: 13 additions & 3 deletions integration/e2e/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ func (s *ConcreteService) Stop() error {
logger.Log(string(out))
return err
}

s.Wait()

s.usedNetworkName = ""

return nil
Expand All @@ -168,15 +171,22 @@ func (s *ConcreteService) Kill() error {
return err
}

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

s.usedNetworkName = ""

return nil
}

// Wait waits until the service is stopped.
func (s *ConcreteService) Wait() {
// Wait until the container actually stopped. However, this could fail if
// the container already exited, so we just ignore the error.
if out, err := RunCommandAndGetOutput("docker", "wait", s.containerName()); err != nil {
logger.Log(string(out))
}
}

// Endpoint returns external (from host perspective) service endpoint (host:port) for given internal port.
// External means that it will be accessible only from host, but not from docker containers.
//
Expand Down

0 comments on commit 61e749e

Please sign in to comment.