@@ -13,34 +13,27 @@ export const REAPER_IMAGE = process.env["RYUK_CONTAINER_IMAGE"]
1313export interface Reaper {
1414 sessionId : string ;
1515
16+ containerId : string ;
17+
1618 addSession ( sessionId : string ) : void ;
1719
1820 addComposeProject ( projectName : string ) : void ;
19-
20- get containerId ( ) : string ;
2121}
2222
23- // see reaper.test.ts for context of this export usage.
24- export type FindReaperContainerFn = ( client : ContainerRuntimeClient ) => Promise < ContainerInfo | undefined > ;
25-
2623let reaper : Reaper ;
2724let sessionId : string ;
2825
29- export async function getReaper (
30- client : ContainerRuntimeClient ,
31- findReaperContainerFn ?: FindReaperContainerFn
32- ) : Promise < Reaper > {
26+ export async function getReaper ( client : ContainerRuntimeClient ) : Promise < Reaper > {
3327 if ( reaper ) {
3428 return reaper ;
3529 }
3630
3731 reaper = await withFileLock ( "testcontainers-node.lock" , async ( ) => {
38- const findReaperFn = findReaperContainerFn ?? findReaperContainerDefault ;
39- const reaperContainer = await findReaperFn ( client ) ;
32+ const reaperContainer = await findReaperContainer ( client ) ;
4033 sessionId = reaperContainer ?. Labels [ LABEL_TESTCONTAINERS_SESSION_ID ] ?? new RandomUuid ( ) . nextUuid ( ) ;
4134
4235 if ( process . env . TESTCONTAINERS_RYUK_DISABLED === "true" ) {
43- return new DisabledReaper ( sessionId ) ;
36+ return new DisabledReaper ( sessionId , "" ) ;
4437 } else if ( reaperContainer ) {
4538 return await useExistingReaper ( reaperContainer , sessionId , client . info . containerRuntime . host ) ;
4639 } else {
@@ -52,7 +45,7 @@ export async function getReaper(
5245 return reaper ;
5346}
5447
55- async function findReaperContainerDefault ( client : ContainerRuntimeClient ) : Promise < ContainerInfo | undefined > {
48+ async function findReaperContainer ( client : ContainerRuntimeClient ) : Promise < ContainerInfo | undefined > {
5649 const containers = await client . container . list ( ) ;
5750 return containers . find (
5851 ( container ) => container . State === "running" && container . Labels [ LABEL_TESTCONTAINERS_RYUK ] === "true"
@@ -69,7 +62,7 @@ async function useExistingReaper(reaperContainer: ContainerInfo, sessionId: stri
6962
7063 const socket = await connectToReaperSocket ( host , reaperPort , reaperContainer . Id ) ;
7164
72- return new RyukReaper ( sessionId , socket , reaperContainer . Id ) ;
65+ return new RyukReaper ( sessionId , reaperContainer . Id , socket ) ;
7366}
7467
7568async function createNewReaper ( sessionId : string , remoteSocketPath : string ) : Promise < Reaper > {
@@ -100,7 +93,7 @@ async function createNewReaper(sessionId: string, remoteSocketPath: string): Pro
10093 startedContainer . getId ( )
10194 ) ;
10295
103- return new RyukReaper ( sessionId , socket , startedContainer . getId ( ) ) ;
96+ return new RyukReaper ( sessionId , startedContainer . getId ( ) , socket ) ;
10497}
10598
10699async function connectToReaperSocket ( host : string , port : number , containerId : string ) : Promise < Socket > {
@@ -146,14 +139,10 @@ async function connectToReaperSocket(host: string, port: number, containerId: st
146139class RyukReaper implements Reaper {
147140 constructor (
148141 public readonly sessionId : string ,
149- private readonly socket : Socket ,
150- private readonly id : string
142+ public readonly containerId : string ,
143+ private readonly socket : Socket
151144 ) { }
152145
153- get containerId ( ) {
154- return this . id ;
155- }
156-
157146 addComposeProject ( projectName : string ) : void {
158147 this . socket . write ( `label=com.docker.compose.project=${ projectName } \r\n` ) ;
159148 }
@@ -164,13 +153,12 @@ class RyukReaper implements Reaper {
164153}
165154
166155class DisabledReaper implements Reaper {
167- constructor ( public readonly sessionId : string ) { }
156+ constructor (
157+ public readonly sessionId : string ,
158+ public readonly containerId : string
159+ ) { }
168160
169161 addComposeProject ( ) : void { }
170162
171163 addSession ( ) : void { }
172-
173- get containerId ( ) {
174- return "" ;
175- }
176164}
0 commit comments