Skip to content

Commit c6fa8b7

Browse files
committed
small tweaks
1 parent 68eb755 commit c6fa8b7

File tree

1 file changed

+10
-20
lines changed
  • internal-packages/testcontainers/src

1 file changed

+10
-20
lines changed

internal-packages/testcontainers/src/index.ts

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ let activeCleanups = 0;
3737
/**
3838
* Logs the cleanup of a resource.
3939
* @param resource - The resource that is being cleaned up.
40-
* @param fn - The cleanup function.
40+
* @param promise - The cleanup promise to await..
4141
*/
42-
async function logCleanup(resource: string, fn: () => Promise<void>) {
42+
async function logCleanup(resource: string, promise: Promise<unknown>) {
4343
const start = new Date();
4444
const order = cleanupOrder++;
4545
const activeAtStart = ++activeCleanups;
4646

4747
let error: unknown = null;
4848
try {
49-
await fn();
49+
await promise;
5050
} catch (err) {
5151
error = err instanceof Error ? err.message : String(err);
5252
}
@@ -58,11 +58,11 @@ async function logCleanup(resource: string, fn: () => Promise<void>) {
5858
console.log(
5959
JSON.stringify({
6060
order,
61+
resource,
62+
durationMs: end.getTime() - start.getTime(),
6163
start: start.toISOString(),
6264
end: end.toISOString(),
6365
parallel,
64-
resource,
65-
durationMs: end.getTime() - start.getTime(),
6666
error,
6767
activeAtStart,
6868
activeAtEnd,
@@ -76,9 +76,7 @@ const network = async ({}, use: Use<StartedNetwork>) => {
7676
await use(network);
7777
} finally {
7878
// Make sure to stop the network after use
79-
await logCleanup("network", async () => {
80-
await network.stop();
81-
});
79+
await logCleanup("network", network.stop());
8280
}
8381
};
8482

@@ -92,9 +90,7 @@ const postgresContainer = async (
9290
} finally {
9391
// WARNING: Testcontainers by default will not wait until the container has stopped. It will simply issue the stop command and return immediately.
9492
// If you need to wait for the container to be stopped, you can provide a timeout. The unit of timeout option here is second
95-
await logCleanup("postgresContainer", async () => {
96-
await container.stop({ timeout: 30 });
97-
});
93+
await logCleanup("postgresContainer", container.stop({ timeout: 30 }));
9894
}
9995
};
10096

@@ -116,9 +112,7 @@ const prisma = async (
116112
try {
117113
await use(prisma);
118114
} finally {
119-
await logCleanup("prisma", async () => {
120-
await prisma.$disconnect();
121-
});
115+
await logCleanup("prisma", prisma.$disconnect());
122116
}
123117
};
124118

@@ -137,9 +131,7 @@ const redisContainer = async (
137131
} finally {
138132
// WARNING: Testcontainers by default will not wait until the container has stopped. It will simply issue the stop command and return immediately.
139133
// If you need to wait for the container to be stopped, you can provide a timeout. The unit of timeout option here is second
140-
await logCleanup("redisContainer", async () => {
141-
await container.stop({ timeout: 30 });
142-
});
134+
await logCleanup("redisContainer", container.stop({ timeout: 30 }));
143135
}
144136
};
145137

@@ -191,9 +183,7 @@ const electricOrigin = async (
191183
} finally {
192184
// WARNING: Testcontainers by default will not wait until the container has stopped. It will simply issue the stop command and return immediately.
193185
// If you need to wait for the container to be stopped, you can provide a timeout. The unit of timeout option here is second
194-
await logCleanup("electricContainer", async () => {
195-
await container.stop({ timeout: 30 });
196-
});
186+
await logCleanup("electricContainer", container.stop({ timeout: 30 }));
197187
}
198188
};
199189

0 commit comments

Comments
 (0)