-
Notifications
You must be signed in to change notification settings - Fork 241
fix: make Application listen promise resolve after aborted #685
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 8 commits
c8dea48
a05a85b
19f37f7
8d7104e
1aa1aa3
046e317
b79df03
cbba826
8526d56
6e01404
22f4b9e
04d4a29
72e54ff
b64b376
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1105,10 +1105,8 @@ Deno.test({ | |
| }); | ||
|
|
||
| Deno.test({ | ||
| name: "Application.listen() - no options", | ||
| name: "Application.listen() - no options - aborted before onListen", | ||
| // ignore: isNode(), | ||
| ignore: true, // there is a challenge with serve and the abort controller that | ||
| // needs to be isolated | ||
| async fn() { | ||
| const controller = new AbortController(); | ||
| const app = new Application(); | ||
|
|
@@ -1118,11 +1116,47 @@ Deno.test({ | |
| const { signal } = controller; | ||
| const p = app.listen({ signal }); | ||
| controller.abort(); | ||
| await p; | ||
| assertRejects( | ||
| async () => await p, | ||
| "aborted prematurely before 'listen' event", | ||
| ); | ||
| teardown(); | ||
| }, | ||
| }); | ||
|
|
||
| Deno.test({ | ||
| name: "Application.listen() - no options - aborted after onListen", | ||
| async fn() { | ||
| const controller = new AbortController(); | ||
| const app = new Application(); | ||
| app.use((ctx) => { | ||
| ctx.response.body = "hello world"; | ||
| }); | ||
| const { signal } = controller; | ||
| const p = app.listen({ signal }); | ||
| app.addEventListener("listen", async () => controller.abort()); | ||
|
kitsonk marked this conversation as resolved.
Outdated
|
||
| const GRACEFUL_TIME = 1000; | ||
| let timer: number | undefined; | ||
| const raceResult = await Promise.race([ | ||
| new Promise(async (resolve) => { | ||
| await p; | ||
| clearTimeout(timer); | ||
|
||
| resolve("resolved cleanly"); | ||
|
kitsonk marked this conversation as resolved.
Outdated
|
||
| }), | ||
| new Promise((resolve) => | ||
| timer = setTimeout( | ||
| () => resolve("likely forever pending"), | ||
| GRACEFUL_TIME, | ||
| ) | ||
| ), | ||
| ]); | ||
| assert( | ||
| raceResult === "resolved cleanly", | ||
| `'listen promise' should resolve before ${GRACEFUL_TIME} ms`, | ||
| ); | ||
|
kitsonk marked this conversation as resolved.
|
||
| }, | ||
| }); | ||
|
|
||
| Deno.test({ | ||
| name: "Application load correct default server", | ||
| ignore: isNode(), // this just hangs on node, because we can't close down | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.