-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test_runner: call abort on test finish #48827
Merged
nodejs-github-bot
merged 12 commits into
nodejs:main
from
rluvaton:call-abort-on-test-finish
Jul 21, 2023
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
21a9e6d
test_runner: call abort on test finish
rluvaton 0ed4cb4
format
rluvaton c4710a8
format
rluvaton eeabcf5
do not recreate on each test
rluvaton f93f38e
cleanup
rluvaton 5017fe5
cleanup
rluvaton 58da4d2
cleanup
rluvaton f5f36b6
abort after all cleanup
rluvaton 0c7c812
Update test/fixtures/test-runner/aborts/wait-for-abort-helper.js
rluvaton 42f7308
Update lib/internal/test_runner/test.js
rluvaton 976b24f
trigger ci
rluvaton e511f95
Revert "trigger ci"
rluvaton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
test/fixtures/test-runner/aborts/failed-test-still-call-abort.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const {test, afterEach} = require('node:test'); | ||
const assert = require('node:assert'); | ||
const { waitForAbort } = require('./wait-for-abort-helper'); | ||
|
||
let testCount = 0; | ||
let signal; | ||
|
||
afterEach(() => { | ||
assert.equal(signal.aborted, false); | ||
|
||
waitForAbort({ testNumber: ++testCount, signal }); | ||
}); | ||
|
||
test("sync", (t) => { | ||
signal = t.signal; | ||
assert.equal(signal.aborted, false); | ||
throw new Error('failing the sync test'); | ||
}); | ||
|
||
test("async", async (t) => { | ||
await null; | ||
signal = t.signal; | ||
assert.equal(signal.aborted, false); | ||
throw new Error('failing the async test'); | ||
}); |
23 changes: 23 additions & 0 deletions
23
test/fixtures/test-runner/aborts/successful-test-still-call-abort.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const {test, afterEach} = require('node:test'); | ||
const assert = require('node:assert'); | ||
const {waitForAbort} = require("./wait-for-abort-helper"); | ||
|
||
let testCount = 0; | ||
let signal; | ||
|
||
afterEach(() => { | ||
assert.equal(signal.aborted, false); | ||
|
||
waitForAbort({ testNumber: ++testCount, signal }); | ||
}); | ||
|
||
test("sync", (t) => { | ||
signal = t.signal; | ||
assert.equal(signal.aborted, false); | ||
}); | ||
|
||
test("async", async (t) => { | ||
await null; | ||
signal = t.signal; | ||
assert.equal(signal.aborted, false); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module.exports = { | ||
waitForAbort: function ({ testNumber, signal }) { | ||
let retries = 0; | ||
|
||
const interval = setInterval(() => { | ||
retries++; | ||
if(signal.aborted) { | ||
console.log(`abort called for test ${testNumber}`); | ||
clearInterval(interval); | ||
return; | ||
} | ||
|
||
if(retries > 100) { | ||
clearInterval(interval); | ||
throw new Error(`abort was not called for test ${testNumber}`); | ||
} | ||
}, 10); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not
await Promise.race(once(signal, 'abort'), setTimeout(1000)
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we wait for the
afterEach
in the test runner...node/lib/internal/test_runner/test.js
Lines 589 to 590 in f5f36b6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so doing await will always fail...