@@ -2,14 +2,15 @@ import { EventStoreDBClient } from '@eventstore/db-client';
22import {
33 AbstractStartedContainer ,
44 GenericContainer ,
5+ Wait ,
56 type StartedTestContainer ,
67} from 'testcontainers' ;
78import type { Environment } from 'testcontainers/build/types' ;
89
910export const EVENTSTOREDB_PORT = 2113 ;
1011export const EVENTSTOREDB_IMAGE_NAME = 'eventstore/eventstore' ;
11- export const EVENTSTOREDB_IMAGE_TAG = '24 .10.0 -bookworm-slim' ;
12- export const EVENTSTOREDB_ARM64_IMAGE_TAG = '24 .10.0 -alpha-arm64v8' ;
12+ export const EVENTSTOREDB_IMAGE_TAG = '23 .10.1 -bookworm-slim' ;
13+ export const EVENTSTOREDB_ARM64_IMAGE_TAG = '23 .10.1 -alpha-arm64v8' ;
1314
1415export const EVENTSTOREDB_DEFAULT_IMAGE = `${ EVENTSTOREDB_IMAGE_NAME } :${ process . arch !== 'arm64' ? EVENTSTOREDB_IMAGE_TAG : EVENTSTOREDB_ARM64_IMAGE_TAG } ` ;
1516
@@ -61,6 +62,10 @@ export class EventStoreDBContainer extends GenericContainer {
6162 this . withEnvironment ( environment ) . withExposedPorts ( EVENTSTOREDB_PORT ) ;
6263
6364 if ( options . withReuse ) this . withReuse ( ) ;
65+
66+ this . withWaitStrategy (
67+ Wait . forAll ( [ Wait . forHealthCheck ( ) , Wait . forListeningPorts ( ) ] ) ,
68+ ) ;
6469 }
6570
6671 async start ( ) : Promise < StartedEventStoreDBContainer > {
@@ -85,29 +90,40 @@ let container: EventStoreDBContainer | null = null;
8590let startedContainer : StartedEventStoreDBContainer | null = null ;
8691let startedCount = 0 ;
8792
88- export const getEventStoreDBTestContainer = async ( ) => {
93+ export const getSharedEventStoreDBTestContainer = async ( ) => {
8994 if ( startedContainer ) return startedContainer ;
9095
9196 if ( ! container )
92- container = new EventStoreDBContainer ( EVENTSTOREDB_DEFAULT_IMAGE ) ;
97+ container = new EventStoreDBContainer ( EVENTSTOREDB_DEFAULT_IMAGE , {
98+ withReuse : true ,
99+ } ) ;
93100
94101 startedContainer = await container . start ( ) ;
95102 startedCount ++ ;
96103
104+ container . withLogConsumer ( ( stream ) =>
105+ stream
106+ . on ( 'data' , ( line ) => console . log ( line ) )
107+ . on ( 'err' , ( line ) => console . error ( line ) )
108+ . on ( 'end' , ( ) => console . log ( 'Stream closed' ) ) ,
109+ ) ;
110+
97111 return startedContainer ;
98112} ;
99113
100114export const getSharedTestEventStoreDBClient = async ( ) => {
101- return ( await getEventStoreDBTestContainer ( ) ) . getClient ( ) ;
115+ return ( await getSharedEventStoreDBTestContainer ( ) ) . getClient ( ) ;
102116} ;
103117
104- export const releaseShartedEventStoreDBTestContainer = async ( ) => {
105- if ( startedContainer && -- startedCount === 0 )
118+ export const releaseSharedEventStoreDBTestContainer = async ( ) => {
119+ const containerToStop = startedContainer ;
120+ if ( containerToStop && -- startedCount === 0 ) {
106121 try {
107- await startedContainer . stop ( ) ;
122+ startedContainer = null ;
123+ container = null ;
124+ await containerToStop . stop ( ) ;
108125 } catch {
109126 /* do nothing */
110127 }
111- container = null ;
112- startedContainer = null ;
128+ }
113129} ;
0 commit comments