diff --git a/test/integration/consul-container/libs/assert/service.go b/test/integration/consul-container/libs/assert/service.go index bc38cc851e..54f8df89b3 100644 --- a/test/integration/consul-container/libs/assert/service.go +++ b/test/integration/consul-container/libs/assert/service.go @@ -75,3 +75,10 @@ func ServiceLogContains(t *testing.T, service libservice.Service, target string) require.NoError(t, err) return strings.Contains(logs, target) } + +// AssertContainerState validates service container status +func AssertContainerState(t *testing.T, service libservice.Service, state string) { + containerStatus, err := service.GetStatus() + require.NoError(t, err) + require.Equal(t, containerStatus, state, fmt.Sprintf("Expected: %s. Got %s", containerStatus, state)) +} diff --git a/test/integration/consul-container/libs/service/connect.go b/test/integration/consul-container/libs/service/connect.go index 9ac54d3bdc..4f22c8b3ac 100644 --- a/test/integration/consul-container/libs/service/connect.go +++ b/test/integration/consul-container/libs/service/connect.go @@ -73,17 +73,22 @@ func (g ConnectContainer) Start() error { if g.container == nil { return fmt.Errorf("container has not been initialized") } - return g.container.Start(context.Background()) + return g.container.Start(g.ctx) } -func (c ConnectContainer) Terminate() error { - return cluster.TerminateContainer(c.ctx, c.container, true) +func (g ConnectContainer) Terminate() error { + return cluster.TerminateContainer(g.ctx, g.container, true) } func (g ConnectContainer) GetAdminAddr() (string, int) { return "localhost", g.adminPort } +func (g ConnectContainer) GetStatus() (string, error) { + state, err := g.container.State(g.ctx) + return state.Status, err +} + // NewConnectService returns a container that runs envoy sidecar, launched by // "consul connect envoy", for service name (serviceName) on the specified // node. The container exposes port serviceBindPort and envoy admin port diff --git a/test/integration/consul-container/libs/service/examples.go b/test/integration/consul-container/libs/service/examples.go index 82c0136080..e4c1fd186a 100644 --- a/test/integration/consul-container/libs/service/examples.go +++ b/test/integration/consul-container/libs/service/examples.go @@ -54,7 +54,7 @@ func (g exampleContainer) Restart() error { } func (g exampleContainer) GetLogs() (string, error) { - rc, err := g.container.Logs(context.Background()) + rc, err := g.container.Logs(g.ctx) if err != nil { return "", fmt.Errorf("could not get logs for example service %s: %w", g.GetServiceName(), err) } @@ -90,6 +90,11 @@ func (c exampleContainer) Terminate() error { return cluster.TerminateContainer(c.ctx, c.container, true) } +func (c exampleContainer) GetStatus() (string, error) { + state, err := c.container.State(c.ctx) + return state.Status, err +} + func NewExampleService(ctx context.Context, name string, httpPort int, grpcPort int, node libcluster.Agent) (Service, error) { namePrefix := fmt.Sprintf("%s-service-example-%s", node.GetDatacenter(), name) containerName := utils.RandName(namePrefix) diff --git a/test/integration/consul-container/libs/service/gateway.go b/test/integration/consul-container/libs/service/gateway.go index d94f5d1aa0..450ef99cbd 100644 --- a/test/integration/consul-container/libs/service/gateway.go +++ b/test/integration/consul-container/libs/service/gateway.go @@ -80,22 +80,27 @@ func (g gatewayContainer) GetAdminAddr() (string, int) { } func (g gatewayContainer) Restart() error { - _, err := g.container.State(context.Background()) + _, err := g.container.State(g.ctx) if err != nil { return fmt.Errorf("error get gateway state %s", err) } - err = g.container.Stop(context.Background(), nil) + err = g.container.Stop(g.ctx, nil) if err != nil { return fmt.Errorf("error stop gateway %s", err) } - err = g.container.Start(context.Background()) + err = g.container.Start(g.ctx) if err != nil { return fmt.Errorf("error start gateway %s", err) } return nil } +func (g gatewayContainer) GetStatus() (string, error) { + state, err := g.container.State(g.ctx) + return state.Status, err +} + func NewGatewayService(ctx context.Context, name string, kind string, node libcluster.Agent) (Service, error) { nodeConfig := node.GetConfig() if nodeConfig.ScratchDir == "" { diff --git a/test/integration/consul-container/libs/service/service.go b/test/integration/consul-container/libs/service/service.go index 75f85a85bf..75a35a74a6 100644 --- a/test/integration/consul-container/libs/service/service.go +++ b/test/integration/consul-container/libs/service/service.go @@ -15,4 +15,5 @@ type Service interface { Start() (err error) Terminate() error Restart() error + GetStatus() (string, error) } diff --git a/test/integration/consul-container/test/basic/connect_service_test.go b/test/integration/consul-container/test/basic/connect_service_test.go index 08eeeb2eec..56c0f28819 100644 --- a/test/integration/consul-container/test/basic/connect_service_test.go +++ b/test/integration/consul-container/test/basic/connect_service_test.go @@ -31,6 +31,7 @@ func TestBasicConnectService(t *testing.T) { libassert.AssertUpstreamEndpointStatus(t, adminPort, "static-server.default", "HEALTHY", 1) libassert.GetEnvoyListenerTCPFilters(t, adminPort) + libassert.AssertContainerState(t, clientService, "running") libassert.HTTPServiceEchoes(t, "localhost", port, "") }