Skip to content

Commit 063bfd2

Browse files
authored
test(functions): resolve flaky test failures from Docker exec cleanup race condition (#1819)
1 parent 3aa0779 commit 063bfd2

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

packages/core/functions-js/test/relay/container.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,22 @@ export class Relay {
2727
this.execCache = execCache
2828
this.execRun = execRun
2929
}
30+
31+
/**
32+
* Safely stops the relay container and cleans up exec processes
33+
*/
34+
async stop(): Promise<void> {
35+
try {
36+
// Try to stop the container - this will trigger cleanup of exec instances
37+
await this.container.stop({ timeout: 5000 })
38+
} catch (error: any) {
39+
// Ignore "no such exec" errors during cleanup - they're harmless
40+
if (!error?.message?.includes('no such exec')) {
41+
throw error
42+
}
43+
// Container is already stopped or exec instances are gone, which is fine
44+
}
45+
}
3046
}
3147

3248
/**
@@ -100,7 +116,7 @@ export async function runRelay(
100116
log(`function started to serve: ${slug + '-' + id}`)
101117
// Add a small delay after health check passes to ensure full readiness
102118
await new Promise((resolve) => setTimeout(resolve, 1000))
103-
return { container: startedRelay, id, execCache, execRun }
119+
return new Relay(startedRelay, id, execCache, execRun)
104120
}
105121
} catch {
106122
/* we actually don't care about errors here */

packages/core/functions-js/test/spec/hello.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ describe('basic tests (hello function)', () => {
1818
})
1919

2020
afterAll(async () => {
21-
relay && relay.container && (await relay.container.stop())
21+
if (relay) {
22+
await relay.stop()
23+
}
2224
})
2325

2426
test('invoke hello with auth header', async () => {

packages/core/functions-js/test/spec/hijack.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ describe('hijack connection', () => {
1818
})
1919

2020
afterAll(async () => {
21-
relay && relay.container && (await relay.container.stop())
21+
if (relay) {
22+
await relay.stop()
23+
}
2224
})
2325

2426
test('invoke func', async () => {

packages/core/functions-js/test/spec/params.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ describe('params reached to function', () => {
2222
})
2323

2424
afterAll(async () => {
25-
relay && relay.container && (await relay.container.stop())
25+
if (relay) {
26+
await relay.stop()
27+
}
2628
})
2729

2830
test('invoke mirror', async () => {

0 commit comments

Comments
 (0)