11import { PostgreSqlContainer , StartedPostgreSqlContainer } from "@testcontainers/postgresql" ;
22import { RedisContainer , StartedRedisContainer } from "@testcontainers/redis" ;
3+ import { tryCatch } from "@trigger.dev/core" ;
34import Redis from "ioredis" ;
45import path from "path" ;
6+ import { isDebug } from "std-env" ;
57import { GenericContainer , StartedNetwork , Wait } from "testcontainers" ;
68import { x } from "tinyexec" ;
79import { expect } from "vitest" ;
@@ -67,7 +69,12 @@ export async function createRedisContainer({
6769 . start ( ) ;
6870
6971 // Add a verification step
70- await verifyRedisConnection ( startedContainer ) ;
72+ const [ error ] = await tryCatch ( verifyRedisConnection ( startedContainer ) ) ;
73+
74+ if ( error ) {
75+ await startedContainer . stop ( { timeout : 30 } ) ;
76+ throw new Error ( "verifyRedisConnection error" , { cause : error } ) ;
77+ }
7178
7279 return {
7380 container : startedContainer ,
@@ -94,11 +101,21 @@ async function verifyRedisConnection(container: StartedRedisContainer) {
94101 } ;
95102
96103 redis . on ( "error" , ( error ) => {
97- console . log ( "verifyRedisConnection error" , error , containerMetadata ) ;
104+ if ( isDebug ) {
105+ console . log ( "verifyRedisConnection: client error" , error , containerMetadata ) ;
106+ }
107+
108+ // Don't throw here, we'll do that below if the ping fails
98109 } ) ;
99110
100111 try {
101112 await redis . ping ( ) ;
113+ } catch ( error ) {
114+ if ( isDebug ) {
115+ console . log ( "verifyRedisConnection: ping error" , error , containerMetadata ) ;
116+ }
117+
118+ throw new Error ( "verifyRedisConnection: ping error" , { cause : error } ) ;
102119 } finally {
103120 await redis . quit ( ) ;
104121 }
0 commit comments