test: Surface container logs on postgres/redis startup failure (#29017)

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Declan Carroll
2026-04-27 12:14:40 +00:00
committed by GitHub
co-authored by Claude Opus 4.6
parent 641d492d56
commit bb0a550039
2 changed files with 33 additions and 19 deletions
@@ -1,6 +1,7 @@
import { PostgreSqlContainer } from '@testcontainers/postgresql';
import type { StartedNetwork } from 'testcontainers';
import { createSilentLogConsumer } from '../helpers/utils';
import { TEST_CONTAINER_IMAGES } from '../test-containers';
import type { Service, ServiceResult } from './types';
@@ -19,7 +20,8 @@ export const postgres: Service<PostgresResult> = {
shouldStart: (ctx) => ctx.usePostgres,
async start(network: StartedNetwork, projectName: string): Promise<PostgresResult> {
const container = await new PostgreSqlContainer(TEST_CONTAINER_IMAGES.postgres)
const { consumer, throwWithLogs } = createSilentLogConsumer();
const builder = new PostgreSqlContainer(TEST_CONTAINER_IMAGES.postgres)
.withNetwork(network)
.withNetworkAliases(HOSTNAME)
.withDatabase('n8n_db')
@@ -45,16 +47,21 @@ export const postgres: Service<PostgresResult> = {
'max_connections=200',
])
.withReuse()
.start();
.withLogConsumer(consumer);
return {
container,
meta: {
database: container.getDatabase(),
username: container.getUsername(),
password: container.getPassword(),
},
};
try {
const container = await builder.start();
return {
container,
meta: {
database: container.getDatabase(),
username: container.getUsername(),
password: container.getPassword(),
},
};
} catch (error: unknown) {
return throwWithLogs(error);
}
},
env(result: PostgresResult, external?: boolean): Record<string, string> {
+16 -9
View File
@@ -1,6 +1,7 @@
import { RedisContainer } from '@testcontainers/redis';
import type { StartedNetwork } from 'testcontainers';
import { createSilentLogConsumer } from '../helpers/utils';
import { TEST_CONTAINER_IMAGES } from '../test-containers';
import type { Service, ServiceResult } from './types';
@@ -18,7 +19,8 @@ export const redis: Service<RedisResult> = {
shouldStart: (ctx) => ctx.isQueueMode,
async start(network: StartedNetwork, projectName: string): Promise<RedisResult> {
const container = await new RedisContainer(TEST_CONTAINER_IMAGES.redis)
const { consumer, throwWithLogs } = createSilentLogConsumer();
const builder = new RedisContainer(TEST_CONTAINER_IMAGES.redis)
.withNetwork(network)
.withNetworkAliases(HOSTNAME)
.withLabels({
@@ -27,15 +29,20 @@ export const redis: Service<RedisResult> = {
})
.withName(`${projectName}-${HOSTNAME}`)
.withReuse()
.start();
.withLogConsumer(consumer);
return {
container,
meta: {
host: HOSTNAME,
port: 6379,
},
};
try {
const container = await builder.start();
return {
container,
meta: {
host: HOSTNAME,
port: 6379,
},
};
} catch (error: unknown) {
return throwWithLogs(error);
}
},
env(result: RedisResult, external?: boolean): Record<string, string> {