From bb0a5500396a87e6be2d7ccc147a708d495b10a4 Mon Sep 17 00:00:00 2001 From: Declan Carroll Date: Mon, 27 Apr 2026 13:14:40 +0100 Subject: [PATCH] test: Surface container logs on postgres/redis startup failure (#29017) Co-authored-by: Claude Opus 4.6 --- .../testing/containers/services/postgres.ts | 27 ++++++++++++------- packages/testing/containers/services/redis.ts | 25 ++++++++++------- 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/packages/testing/containers/services/postgres.ts b/packages/testing/containers/services/postgres.ts index 1b882a1d62d..03569d2cd06 100644 --- a/packages/testing/containers/services/postgres.ts +++ b/packages/testing/containers/services/postgres.ts @@ -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 = { shouldStart: (ctx) => ctx.usePostgres, async start(network: StartedNetwork, projectName: string): Promise { - 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 = { '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 { diff --git a/packages/testing/containers/services/redis.ts b/packages/testing/containers/services/redis.ts index bd92b162961..3f3b9535d1a 100644 --- a/packages/testing/containers/services/redis.ts +++ b/packages/testing/containers/services/redis.ts @@ -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 = { shouldStart: (ctx) => ctx.isQueueMode, async start(network: StartedNetwork, projectName: string): Promise { - 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 = { }) .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 {