test(backend): allow a slow Kafka start and log its tail on failure
This commit is contained in:
1 parent
8378ad45b0
commit
7e80c8ad2a
2 files changed
+35
-5
No files matched your search
@@ -53,7 +53,11 @@ const (
|
|||||||
readinessTimeout = 5 * time.Second
|
readinessTimeout = 5 * time.Second
|
||||||
redisTimeout = 300 * time.Millisecond
|
redisTimeout = 300 * time.Millisecond
|
||||||
storageTimeout = 2 * time.Second
|
storageTimeout = 2 * time.Second
|
||||||
kafkaStartupTimeout = time.Minute
|
// 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
|
kafkaReadyTimeout = 30 * time.Second
|
||||||
|
|
||||||
seaweedfsS3Port = "8333/tcp"
|
seaweedfsS3Port = "8333/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) {
|
func (env *testEnvironment) startPostgres(ctx context.Context, t *testing.T) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
container, err := postgres.Run(ctx, postgresImage,
|
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")
|
env.cleanupContainer(ctx, container, "Kafka")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
logContainerTail(ctx, t, container, "Kafka")
|
||||||
t.Fatalf("start Kafka container: %v", err)
|
t.Fatalf("start Kafka container: %v", err)
|
||||||
}
|
}
|
||||||
env.kafkaContainer = container
|
env.kafkaContainer = container
|
||||||
|
|||||||
@@ -610,7 +610,7 @@ func newConsumerGroup() string {
|
|||||||
|
|
||||||
// newSource creates a group member for topic. close leaves the group; it
|
// newSource creates a group member for topic. close leaves the group; it
|
||||||
// also runs when t finishes, after the consumer stopped.
|
// 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()
|
t.Helper()
|
||||||
settings := harness.env.Config
|
settings := harness.env.Config
|
||||||
settings.KafkaEventsTopic = topic
|
settings.KafkaEventsTopic = topic
|
||||||
@@ -620,9 +620,9 @@ func (harness *consumerHarness) newSource(t *testing.T, topic, group string) (so
|
|||||||
t.Fatalf("NewEventSource() error = %v", err)
|
t.Fatalf("NewEventSource() error = %v", err)
|
||||||
}
|
}
|
||||||
var once sync.Once
|
var once sync.Once
|
||||||
close = func() { once.Do(closeSource) }
|
closeOnce = func() { once.Do(closeSource) }
|
||||||
t.Cleanup(close)
|
t.Cleanup(closeOnce)
|
||||||
return source, close
|
return source, closeOnce
|
||||||
}
|
}
|
||||||
|
|
||||||
func (harness *consumerHarness) startConsumer(
|
func (harness *consumerHarness) startConsumer(
|
||||||
|
|||||||
Reference in new issue
Block a user