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
+36
-6
No files matched your search
@@ -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
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in new issue
Block a user