Skip to content

Commit

Permalink
Print container logs when integration test fails (#1127)
Browse files Browse the repository at this point in the history
We see (relatively rarely) integration tests being flaky. In those cases
of flakiness the current logging is not sufficient to really understand
the cause of the problem.

This PR aims to improve logging by printing logs of all containers when
a test fails.

`printContainerLogs` is added to `Containers.Cleanup()` code to print
the logs of containers.

Additionally, the `Cleanup()` function is now **always** called, even if
the containers failed to start or tests failed. To make sure it can
print some logs:
- the code now has less panics, which would have prevented `Cleanup()`
from running
- in `setupClickHouse()` and others we return the container object in
case container failed to start instead of `nil` (but still with error)
to be able to recover some logs
- if one container fails to start, `Containers` is now returned
partially filled (but still with error), so that we can print some logs
instead of giving up entirely

---------

Signed-off-by: Piotr Grabowski <[email protected]>
Co-authored-by: Jacek Migdal <[email protected]>
  • Loading branch information
avelanarius and jakozaur authored Dec 20, 2024
1 parent cb7b0cf commit 1a78cdf
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 84 deletions.
2 changes: 1 addition & 1 deletion ci/it/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import (

func runIntegrationTest(t *testing.T, testCase testcases.TestCase) {
ctx := context.Background()
defer testCase.Cleanup(ctx, t)
if err := testCase.SetupContainers(ctx); err != nil {
t.Fatalf("Failed to setup containers: %s", err)
}
if err := testCase.RunTests(ctx, t); err != nil {
t.Fatalf("Failed to run tests: %s", err)
}
testCase.Cleanup(ctx)
}

func TestTransparentProxy(t *testing.T) {
Expand Down
8 changes: 5 additions & 3 deletions ci/it/testcases/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
type TestCase interface {
SetupContainers(ctx context.Context) error
RunTests(ctx context.Context, t *testing.T) error
Cleanup(ctx context.Context)
Cleanup(ctx context.Context, t *testing.T)
}

type IntegrationTestcaseBase struct {
Expand All @@ -36,8 +36,10 @@ func (tc *IntegrationTestcaseBase) RunTests(ctx context.Context, t *testing.T) e
return nil
}

func (tc *IntegrationTestcaseBase) Cleanup(ctx context.Context) {
tc.Containers.Cleanup(ctx)
func (tc *IntegrationTestcaseBase) Cleanup(ctx context.Context, t *testing.T) {
if tc.Containers != nil {
tc.Containers.Cleanup(ctx, t)
}
}

func (tc *IntegrationTestcaseBase) getQuesmaEndpoint() string {
Expand Down
5 changes: 1 addition & 4 deletions ci/it/testcases/test_ab.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,8 @@ func NewABTestcase() *ABTestcase {

func (a *ABTestcase) SetupContainers(ctx context.Context) error {
containers, err := setupAllContainersWithCh(ctx, a.ConfigTemplate)
if err != nil {
return err
}
a.Containers = containers
return nil
return err
}

func (a *ABTestcase) RunTests(ctx context.Context, t *testing.T) error {
Expand Down
5 changes: 1 addition & 4 deletions ci/it/testcases/test_dual_write_and_common_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,8 @@ func NewDualWriteAndCommonTableTestcase() *DualWriteAndCommonTableTestcase {

func (a *DualWriteAndCommonTableTestcase) SetupContainers(ctx context.Context) error {
containers, err := setupAllContainersWithCh(ctx, a.ConfigTemplate)
if err != nil {
return err
}
a.Containers = containers
return nil
return err
}

func (a *DualWriteAndCommonTableTestcase) RunTests(ctx context.Context, t *testing.T) error {
Expand Down
5 changes: 1 addition & 4 deletions ci/it/testcases/test_ingest.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,8 @@ func NewIngestTestcase() *IngestTestcase {

func (a *IngestTestcase) SetupContainers(ctx context.Context) error {
containers, err := setupAllContainersWithCh(ctx, a.ConfigTemplate)
if err != nil {
return err
}
a.Containers = containers
return nil
return err
}

func (a *IngestTestcase) RunTests(ctx context.Context, t *testing.T) error {
Expand Down
5 changes: 1 addition & 4 deletions ci/it/testcases/test_reading_clickhouse_tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,8 @@ func NewReadingClickHouseTablesIntegrationTestcase() *ReadingClickHouseTablesInt

func (a *ReadingClickHouseTablesIntegrationTestcase) SetupContainers(ctx context.Context) error {
containers, err := setupAllContainersWithCh(ctx, a.ConfigTemplate)
if err != nil {
return err
}
a.Containers = containers
return nil
return err
}

func (a *ReadingClickHouseTablesIntegrationTestcase) RunTests(ctx context.Context, t *testing.T) error {
Expand Down
5 changes: 1 addition & 4 deletions ci/it/testcases/test_transparent_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@ func NewTransparentProxyIntegrationTestcase() *TransparentProxyIntegrationTestca

func (a *TransparentProxyIntegrationTestcase) SetupContainers(ctx context.Context) error {
containers, err := setupContainersForTransparentProxy(ctx, a.ConfigTemplate)
if err != nil {
return err
}
a.Containers = containers
return nil
return err
}

func (a *TransparentProxyIntegrationTestcase) RunTests(ctx context.Context, t *testing.T) error {
Expand Down
5 changes: 1 addition & 4 deletions ci/it/testcases/test_two_pipelines.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@ func NewQueryAndIngestPipelineTestcase() *QueryAndIngestPipelineTestcase {

func (a *QueryAndIngestPipelineTestcase) SetupContainers(ctx context.Context) error {
containers, err := setupAllContainersWithCh(ctx, a.ConfigTemplate)
if err != nil {
return err
}
a.Containers = containers
return nil
return err
}

func (a *QueryAndIngestPipelineTestcase) RunTests(ctx context.Context, t *testing.T) error {
Expand Down
5 changes: 1 addition & 4 deletions ci/it/testcases/test_wildcard_clickhouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@ func NewWildcardClickhouseTestcase() *WildcardClickhouseTestcase {

func (a *WildcardClickhouseTestcase) SetupContainers(ctx context.Context) error {
containers, err := setupAllContainersWithCh(ctx, a.ConfigTemplate)
if err != nil {
return err
}
a.Containers = containers
return nil
return err
}

func (a *WildcardClickhouseTestcase) RunTests(ctx context.Context, t *testing.T) error {
Expand Down
5 changes: 1 addition & 4 deletions ci/it/testcases/test_wildcard_disabled.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@ func NewWildcardDisabledTestcase() *WildcardDisabledTestcase {

func (a *WildcardDisabledTestcase) SetupContainers(ctx context.Context) error {
containers, err := setupAllContainersWithCh(ctx, a.ConfigTemplate)
if err != nil {
return err
}
a.Containers = containers
return nil
return err
}

func (a *WildcardDisabledTestcase) RunTests(ctx context.Context, t *testing.T) error {
Expand Down
Loading

0 comments on commit 1a78cdf

Please sign in to comment.