Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 814d059

Browse filesBrowse files
authored
test: wait for background work to finish in integration tests (#2851)
1 parent d30bca4 commit 814d059
Copy full SHA for 814d059

File tree

Expand file treeCollapse file tree

1 file changed

+18
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+18
-0
lines changed

‎tests/utils/fixture.ts

Copy file name to clipboardExpand all lines: tests/utils/fixture.ts
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,12 @@ export async function invokeFunction(
396396
process.env[key] = environment[key]
397397
})
398398

399+
let resolveInvocation, rejectInvocation
400+
const invocationPromise = new Promise((resolve, reject) => {
401+
resolveInvocation = resolve
402+
rejectInvocation = reject
403+
})
404+
399405
const response = (await execute({
400406
event: {
401407
headers: headers || {},
@@ -405,8 +411,20 @@ export async function invokeFunction(
405411
},
406412
lambdaFunc: { handler },
407413
timeoutMs: 4_000,
414+
onInvocationEnd: (error) => {
415+
// lambda-local resolve promise return from execute when response is closed
416+
// but we should wait for tracked background work to finish
417+
// before resolving the promise to allow background work to finish
418+
if (error) {
419+
rejectInvocation(error)
420+
} else {
421+
resolveInvocation()
422+
}
423+
},
408424
})) as LambdaResponse
409425

426+
await invocationPromise
427+
410428
const responseHeaders = Object.entries(response.multiValueHeaders || {}).reduce(
411429
(prev, [key, value]) => ({
412430
...prev,

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.