-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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: pass abort signal to test #43554
Merged
nodejs-github-bot
merged 2 commits into
nodejs:main
from
MoLow:test-runner-abort-signal
Jul 20, 2022
+586
−81
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
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
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,47 @@ | ||
// Flags: --no-warnings | ||
'use strict'; | ||
require('../common'); | ||
const test = require('node:test'); | ||
|
||
test('promise timeout signal', { signal: AbortSignal.timeout(1) }, async (t) => { | ||
await Promise.all([ | ||
t.test('ok 1', async () => {}), | ||
t.test('ok 2', () => {}), | ||
t.test('ok 3', { signal: t.signal }, async () => {}), | ||
t.test('ok 4', { signal: t.signal }, () => {}), | ||
t.test('not ok 1', () => new Promise(() => {})), | ||
t.test('not ok 2', (t, done) => {}), | ||
t.test('not ok 3', { signal: t.signal }, () => new Promise(() => {})), | ||
t.test('not ok 4', { signal: t.signal }, (t, done) => {}), | ||
t.test('not ok 5', { signal: t.signal }, (t, done) => { | ||
t.signal.addEventListener('abort', done); | ||
}), | ||
]); | ||
}); | ||
|
||
test('promise abort signal', { signal: AbortSignal.abort() }, async (t) => { | ||
await t.test('should not appear', () => {}); | ||
}); | ||
|
||
test('callback timeout signal', { signal: AbortSignal.timeout(1) }, (t, done) => { | ||
t.test('ok 1', async () => {}); | ||
t.test('ok 2', () => {}); | ||
t.test('ok 3', { signal: t.signal }, async () => {}); | ||
t.test('ok 4', { signal: t.signal }, () => {}); | ||
t.test('not ok 1', () => new Promise(() => {})); | ||
t.test('not ok 2', (t, done) => {}); | ||
t.test('not ok 3', { signal: t.signal }, () => new Promise(() => {})); | ||
t.test('not ok 4', { signal: t.signal }, (t, done) => {}); | ||
t.test('not ok 5', { signal: t.signal }, (t, done) => { | ||
t.signal.addEventListener('abort', done); | ||
}); | ||
}); | ||
|
||
test('callback abort signal', { signal: AbortSignal.abort() }, (t, done) => { | ||
t.test('should not appear', done); | ||
}); | ||
|
||
// AbortSignal.timeout(1) doesn't prevent process from closing | ||
// thus we have to keep the process open to prevent cancelation | ||
// of the entire test tree | ||
setTimeout(() => {}, 1000); |
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,249 @@ | ||
TAP version 13 | ||
# Subtest: promise timeout signal | ||
# Subtest: ok 1 | ||
ok 1 - ok 1 | ||
--- | ||
duration_ms: * | ||
... | ||
# Subtest: ok 2 | ||
ok 2 - ok 2 | ||
--- | ||
duration_ms: * | ||
... | ||
# Subtest: ok 3 | ||
ok 3 - ok 3 | ||
--- | ||
duration_ms: * | ||
... | ||
# Subtest: ok 4 | ||
ok 4 - ok 4 | ||
--- | ||
duration_ms: * | ||
... | ||
# Subtest: not ok 1 | ||
not ok 5 - not ok 1 | ||
--- | ||
duration_ms: * | ||
failureType: 'cancelledByParent' | ||
error: 'test did not finish before its parent and was cancelled' | ||
code: 'ERR_TEST_FAILURE' | ||
... | ||
# Subtest: not ok 2 | ||
not ok 6 - not ok 2 | ||
--- | ||
duration_ms: * | ||
failureType: 'cancelledByParent' | ||
error: 'test did not finish before its parent and was cancelled' | ||
code: 'ERR_TEST_FAILURE' | ||
... | ||
# Subtest: not ok 3 | ||
not ok 7 - not ok 3 | ||
--- | ||
duration_ms: * | ||
error: 'This operation was aborted' | ||
code: 20 | ||
stack: |- | ||
* | ||
* | ||
* | ||
* | ||
* | ||
* | ||
* | ||
* | ||
* | ||
* | ||
... | ||
# Subtest: not ok 4 | ||
not ok 8 - not ok 4 | ||
--- | ||
duration_ms: * | ||
error: 'This operation was aborted' | ||
code: 20 | ||
stack: |- | ||
* | ||
* | ||
* | ||
* | ||
* | ||
* | ||
* | ||
* | ||
* | ||
* | ||
... | ||
# Subtest: not ok 5 | ||
not ok 9 - not ok 5 | ||
--- | ||
duration_ms: * | ||
error: 'This operation was aborted' | ||
code: 20 | ||
stack: |- | ||
* | ||
* | ||
* | ||
* | ||
* | ||
* | ||
* | ||
* | ||
* | ||
* | ||
... | ||
1..9 | ||
not ok 1 - promise timeout signal | ||
--- | ||
duration_ms: * | ||
error: 'The operation was aborted due to timeout' | ||
code: 23 | ||
stack: |- | ||
* | ||
* | ||
* | ||
* | ||
... | ||
# Subtest: promise abort signal | ||
not ok 2 - promise abort signal | ||
--- | ||
duration_ms: * | ||
error: 'This operation was aborted' | ||
code: 20 | ||
stack: |- | ||
* | ||
* | ||
* | ||
* | ||
* | ||
* | ||
* | ||
* | ||
* | ||
... | ||
# Subtest: callback timeout signal | ||
# Subtest: ok 1 | ||
ok 1 - ok 1 | ||
--- | ||
duration_ms: * | ||
... | ||
# Subtest: ok 2 | ||
ok 2 - ok 2 | ||
--- | ||
duration_ms: * | ||
... | ||
# Subtest: ok 3 | ||
ok 3 - ok 3 | ||
--- | ||
duration_ms: * | ||
... | ||
# Subtest: ok 4 | ||
ok 4 - ok 4 | ||
--- | ||
duration_ms: * | ||
... | ||
# Subtest: not ok 1 | ||
not ok 5 - not ok 1 | ||
--- | ||
duration_ms: * | ||
failureType: 'cancelledByParent' | ||
error: 'test did not finish before its parent and was cancelled' | ||
code: 'ERR_TEST_FAILURE' | ||
... | ||
# Subtest: not ok 2 | ||
not ok 6 - not ok 2 | ||
--- | ||
duration_ms: * | ||
failureType: 'cancelledByParent' | ||
error: 'test did not finish before its parent and was cancelled' | ||
code: 'ERR_TEST_FAILURE' | ||
... | ||
# Subtest: not ok 3 | ||
not ok 7 - not ok 3 | ||
--- | ||
duration_ms: * | ||
error: 'This operation was aborted' | ||
code: 20 | ||
stack: |- | ||
* | ||
* | ||
* | ||
* | ||
* | ||
* | ||
* | ||
* | ||
* | ||
* | ||
... | ||
# Subtest: not ok 4 | ||
not ok 8 - not ok 4 | ||
--- | ||
duration_ms: * | ||
error: 'This operation was aborted' | ||
code: 20 | ||
stack: |- | ||
* | ||
* | ||
* | ||
* | ||
* | ||
* | ||
* | ||
* | ||
* | ||
* | ||
... | ||
# Subtest: not ok 5 | ||
not ok 9 - not ok 5 | ||
--- | ||
duration_ms: * | ||
error: 'This operation was aborted' | ||
code: 20 | ||
stack: |- | ||
* | ||
* | ||
* | ||
* | ||
* | ||
* | ||
* | ||
* | ||
* | ||
* | ||
... | ||
1..9 | ||
not ok 3 - callback timeout signal | ||
--- | ||
duration_ms: * | ||
error: 'The operation was aborted due to timeout' | ||
code: 23 | ||
stack: |- | ||
* | ||
* | ||
* | ||
* | ||
... | ||
# Subtest: callback abort signal | ||
not ok 4 - callback abort signal | ||
--- | ||
duration_ms: * | ||
error: 'This operation was aborted' | ||
code: 20 | ||
stack: |- | ||
* | ||
* | ||
* | ||
* | ||
* | ||
* | ||
* | ||
* | ||
* | ||
... | ||
1..4 | ||
# tests 4 | ||
# pass 0 | ||
# fail 0 | ||
# cancelled 4 | ||
# skipped 0 | ||
# todo 0 | ||
# duration_ms * |
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,27 @@ | ||
// Flags: --no-warnings | ||
'use strict'; | ||
require('../common'); | ||
const { describe, it } = require('node:test'); | ||
|
||
describe('describe timeout signal', { signal: AbortSignal.timeout(1) }, (t) => { | ||
it('ok 1', async () => {}); | ||
it('ok 2', () => {}); | ||
it('ok 3', { signal: t.signal }, async () => {}); | ||
it('ok 4', { signal: t.signal }, () => {}); | ||
it('not ok 1', () => new Promise(() => {})); | ||
it('not ok 2', (done) => {}); | ||
it('not ok 3', { signal: t.signal }, () => new Promise(() => {})); | ||
it('not ok 4', { signal: t.signal }, (done) => {}); | ||
it('not ok 5', { signal: t.signal }, function(done) { | ||
this.signal.addEventListener('abort', done); | ||
}); | ||
}); | ||
|
||
describe('describe abort signal', { signal: AbortSignal.abort() }, () => { | ||
it('should not appear', () => {}); | ||
}); | ||
|
||
// AbortSignal.timeout(1) doesn't prevent process from closing | ||
// thus we have to keep the process open to prevent cancelation | ||
// of the entire test tree | ||
setTimeout(() => {}, 1000); |
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,99 @@ | ||
TAP version 13 | ||
# Subtest: describe timeout signal | ||
# Subtest: ok 1 | ||
ok 1 - ok 1 | ||
--- | ||
duration_ms: * | ||
... | ||
# Subtest: ok 2 | ||
ok 2 - ok 2 | ||
--- | ||
duration_ms: * | ||
... | ||
# Subtest: ok 3 | ||
ok 3 - ok 3 | ||
--- | ||
duration_ms: * | ||
... | ||
# Subtest: ok 4 | ||
ok 4 - ok 4 | ||
--- | ||
duration_ms: * | ||
... | ||
# Subtest: not ok 1 | ||
not ok 5 - not ok 1 | ||
--- | ||
duration_ms: * | ||
failureType: 'cancelledByParent' | ||
error: 'test did not finish before its parent and was cancelled' | ||
code: 'ERR_TEST_FAILURE' | ||
... | ||
# Subtest: not ok 2 | ||
not ok 6 - not ok 2 | ||
--- | ||
duration_ms: * | ||
failureType: 'cancelledByParent' | ||
error: 'test did not finish before its parent and was cancelled' | ||
code: 'ERR_TEST_FAILURE' | ||
... | ||
# Subtest: not ok 3 | ||
not ok 7 - not ok 3 | ||
--- | ||
duration_ms: * | ||
failureType: 'cancelledByParent' | ||
error: 'test did not finish before its parent and was cancelled' | ||
code: 'ERR_TEST_FAILURE' | ||
... | ||
# Subtest: not ok 4 | ||
not ok 8 - not ok 4 | ||
--- | ||
duration_ms: * | ||
failureType: 'cancelledByParent' | ||
error: 'test did not finish before its parent and was cancelled' | ||
code: 'ERR_TEST_FAILURE' | ||
... | ||
# Subtest: not ok 5 | ||
not ok 9 - not ok 5 | ||
--- | ||
duration_ms: * | ||
failureType: 'cancelledByParent' | ||
error: 'test did not finish before its parent and was cancelled' | ||
code: 'ERR_TEST_FAILURE' | ||
... | ||
1..9 | ||
not ok 1 - describe timeout signal | ||
--- | ||
duration_ms: * | ||
error: 'The operation was aborted due to timeout' | ||
code: 23 | ||
stack: |- | ||
* | ||
* | ||
* | ||
* | ||
... | ||
# Subtest: describe abort signal | ||
not ok 2 - describe abort signal | ||
--- | ||
duration_ms: * | ||
error: 'This operation was aborted' | ||
code: 20 | ||
stack: |- | ||
* | ||
* | ||
* | ||
* | ||
* | ||
* | ||
* | ||
* | ||
* | ||
... | ||
1..2 | ||
# tests 2 | ||
# pass 0 | ||
# fail 0 | ||
# cancelled 2 | ||
# skipped 0 | ||
# todo 0 | ||
# duration_ms * |
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
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.
I don't think this is correct, we should keep that property as a string – also, you may think that the stack is not useful, but why is that a good reason to remove it?
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.
although I agree - this was here before this PR so I think it is out of scope