diff --git a/backend/integration_test/bootstrap_test.go b/backend/integration_test/bootstrap_test.go index b2249f9..5c51e73 100644 --- a/backend/integration_test/bootstrap_test.go +++ b/backend/integration_test/bootstrap_test.go @@ -53,8 +53,12 @@ const ( readinessTimeout = 5 * time.Second redisTimeout = 300 * time.Millisecond storageTimeout = 2 * time.Second - kafkaStartupTimeout = time.Minute - kafkaReadyTimeout = 30 * time.Second + // A cold JVM start under a busy Docker daemon, for example while other + // suites start containers, has exceeded one minute. + kafkaStartupTimeout = 3 * time.Minute + // startupLogTail bounds the container log printed when a start fails. + startupLogTail = 8 << 10 + kafkaReadyTimeout = 30 * time.Second seaweedfsS3Port = "8333/tcp" seaweedfsFilerPort = "8888/tcp" @@ -176,6 +180,31 @@ func (env *testEnvironment) cleanupContainer(ctx context.Context, container test }) } +// logContainerTail prints the end of a container log after a failed start, +// so a startup timeout shows what the service was doing. +func logContainerTail(ctx context.Context, t *testing.T, container testcontainers.Container, name string) { + t.Helper() + if container == nil { + return + } + ctx, cancel := context.WithTimeout(context.WithoutCancel(ctx), cleanupTimeout) + defer cancel() + logs, err := container.Logs(ctx) + if err != nil { + t.Logf("read %s container log: %v", name, err) + return + } + defer logs.Close() + data, err := io.ReadAll(logs) + if err != nil { + t.Logf("read %s container log: %v", name, err) + } + if len(data) > startupLogTail { + data = data[len(data)-startupLogTail:] + } + t.Logf("%s container log tail:\n%s", name, data) +} + func (env *testEnvironment) startPostgres(ctx context.Context, t *testing.T) { t.Helper() container, err := postgres.Run(ctx, postgresImage, @@ -400,6 +429,7 @@ func (env *testEnvironment) startKafka(ctx context.Context, t *testing.T) { }) env.cleanupContainer(ctx, container, "Kafka") if err != nil { + logContainerTail(ctx, t, container, "Kafka") t.Fatalf("start Kafka container: %v", err) } env.kafkaContainer = container diff --git a/backend/integration_test/event_consumer_test.go b/backend/integration_test/event_consumer_test.go index dc3bb08..3462bde 100644 --- a/backend/integration_test/event_consumer_test.go +++ b/backend/integration_test/event_consumer_test.go @@ -610,7 +610,7 @@ func newConsumerGroup() string { // newSource creates a group member for topic. close leaves the group; it // also runs when t finishes, after the consumer stopped. -func (harness *consumerHarness) newSource(t *testing.T, topic, group string) (source *kafka.EventSource, close func()) { +func (harness *consumerHarness) newSource(t *testing.T, topic, group string) (source *kafka.EventSource, closeOnce func()) { t.Helper() settings := harness.env.Config settings.KafkaEventsTopic = topic @@ -620,9 +620,9 @@ func (harness *consumerHarness) newSource(t *testing.T, topic, group string) (so t.Fatalf("NewEventSource() error = %v", err) } var once sync.Once - close = func() { once.Do(closeSource) } - t.Cleanup(close) - return source, close + closeOnce = func() { once.Do(closeSource) } + t.Cleanup(closeOnce) + return source, closeOnce } func (harness *consumerHarness) startConsumer(