Skip to content

Commit 24e8624

Browse files
authored
fix(e2e): Fix flaky Test_VerifyComponentsAreSuccessfullyStarted_WithRuntimeConfigLoad (#7502)
When a service fails during WaitReady (container starts but crashes due to runtime config validation), it remains registered in the scenario's services slice. The next attempt to start a service with the same name then fails with "another service with the same name has already been started". Fix by: 1. Calling s.Stop() after expected StartAndWaitReady failures to unregister the service before retrying with a new instance. 2. Making ConcreteService.Stop() and Kill() tolerant of already-removed containers (started with --rm flag) by treating "No such container" errors as successful stops. Signed-off-by: Ben Ye <benye@amazon.com>
1 parent 5099e71 commit 24e8624

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

integration/e2e/service.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,12 @@ func (s *ConcreteService) Stop() error {
156156
logger.Log("Stopping", s.name)
157157

158158
if out, err := RunCommandAndGetOutput("docker", "stop", "--time=30", s.containerName()); err != nil {
159+
// If the container has already exited and been removed (e.g., started
160+
// with --rm), treat it as a successful stop.
161+
if strings.Contains(string(out), "No such container") {
162+
s.usedNetworkName = ""
163+
return nil
164+
}
159165
logger.Log(string(out))
160166
return err
161167
}
@@ -181,6 +187,12 @@ func (s *ConcreteService) Kill() error {
181187
logger.Log("Killing", s.name)
182188

183189
if out, err := RunCommandAndGetOutput("docker", "kill", s.containerName()); err != nil {
190+
// If the container has already exited and been removed (e.g., started
191+
// with --rm), treat it as a successful kill.
192+
if strings.Contains(string(out), "No such container") {
193+
s.usedNetworkName = ""
194+
return nil
195+
}
184196
logger.Log(string(out))
185197
return err
186198
}

integration/runtime_config_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,10 @@ overrides:
215215
"-querier.store-gateway-addresses": strings.Join([]string{storeGateway.NetworkGRPCEndpoint()}, ","),
216216
}), "")
217217
require.Error(t, s.StartAndWaitReady(querier))
218+
// Stop the failed service to unregister it before retrying with the same name.
219+
// Ignore error: if the container crashed before Start() completed, the service
220+
// was never registered and Stop() returns "does not exist" which is fine.
221+
_ = s.Stop(querier)
218222

219223
// Start Query frontend
220224
queryFrontend := e2ecortex.NewQueryFrontendWithConfigFile("query-frontend", "", flags, "")
@@ -231,6 +235,8 @@ overrides:
231235
// Ruler start, but fail with "-distributor.shard-by-all-labels": "false"
232236
ruler := e2ecortex.NewRuler("ruler", consul.NetworkHTTPEndpoint(), mergeFlags(flags, RulerFlags()), "")
233237
require.Error(t, s.StartAndWaitReady(ruler))
238+
// Stop the failed service to unregister it before retrying with the same name.
239+
_ = s.Stop(ruler)
234240

235241
// Ruler start, should success with "-distributor.shard-by-all-labels": "true"
236242
ruler = e2ecortex.NewRuler("ruler", consul.NetworkHTTPEndpoint(), mergeFlags(flags, RulerFlags(), map[string]string{
@@ -249,6 +255,8 @@ overrides:
249255
// Distributor start, but fail with "-distributor.shard-by-all-labels": "false"
250256
distributor := e2ecortex.NewQuerier("distributor", e2ecortex.RingStoreConsul, consul.NetworkHTTPEndpoint(), mergeFlags(flags, map[string]string{}), "")
251257
require.Error(t, s.StartAndWaitReady(distributor))
258+
// Stop the failed service to unregister it before retrying with the same name.
259+
_ = s.Stop(distributor)
252260

253261
// Distributor start, should success with "-distributor.shard-by-all-labels": "true"
254262
distributor = e2ecortex.NewQuerier("distributor", e2ecortex.RingStoreConsul, consul.NetworkHTTPEndpoint(), mergeFlags(flags, map[string]string{

0 commit comments

Comments
 (0)