GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||
GeezerVison is showing github.com — test_runner: cleanup test timeout abort listener by rluvaton · Pull Request #48915 · nodejs/node Conversation
|
|
Review requested:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I wanted to put this in the setTimeout but for some reason, the test-runner-output.mjs test failed for the describe_it file with some missing stack trace
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Done this to match the current behavior:
Line 48 in 78f6952
| reject(new AbortError(undefined, { cause: signal?.reason })); |
but we should align it with just using an abort signal with no timeout - no error being thrown or throw an abort error
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Could/Should this be an AbortSignal.any([signal, AbortSignal.timeout(timeout)]) etc?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I don't think it would change anything as the timer won't get cleaned...
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
What do you mean about the timer not getting clean?
The AbortSignal.any uses weak refs, so once this is GCed it would clear the timeout...
I think this suggestion could potentially reduce the complexity here, and also make it easier to land on v18, which doesn't have dispose & addAbortListener at the moment
WDYT?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
thank you! this is a much cleaner solution! the only problem here is that we create 2 new AbortSignal (AbortSignal.any and AbortSignal.timeout) for every describe/test/hook run, which can be bad for performance...
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
@MoLow what do you think? should we remove the addAbortListener and dispose in order to support v18 and v16?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I don't think this actually simplifies 😬
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
@rluvaton I had something like this in mind:
function stopTest(timeout, signal) { const timeoutSignal = timeout !== kDefaultTimeout && AbortSignal.timeout(timeout); const composedSignal = AbortSignal.any([signal, timeoutSignal].filter(Boolean)); return PromisePrototypeThen(once(composedSignal, 'abort'), (e) => { if (e.target.reason !== timeoutSignal.reason) { return; } throw new ERR_TEST_FAILURE( `test timed out after ${timeout}ms`, kTestTimeoutFailure, ); }) };
But current solution works for me 🙂
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
If we accept the extra creation of an abort signal I highly prefer that
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I assume we would want to profile both and decide based on that?
@MoLow @benjamingr what is your opinion here?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I've created a benchmark PR and after it is merged we can check different solutions:
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
What do you mean about the timer not getting clean?
The AbortSignal.any uses weak refs, so once this is GCed it would clear the timeout...
I think this suggestion could potentially reduce the complexity here, and also make it easier to land on v18, which doesn't have dispose & addAbortListener at the moment
WDYT?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
@MoLow updated with your changes and modified to use |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I don't like the promise+disposer in one object code pattern here + I don't like the explicit promise construction here.
We're core, we can "cheat", we can add the listener with [kWeakHandler]: test and it will cleanup the listener when the test is done.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
to which listener? the abort listener? because using the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
The issue is the listener won't be removed right? kWeakListener means "remove the listener when that resource is gcd" |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
(I removed the timeout support so I try to make it work for the simple case) I understand, but when I tried changing the const { aborted } = require('internal/abort_controller'); function stopTest(timeout, signal) { return aborted(signal, {}); } The test I wrote: const { beforeEach, afterEach, test} = require("node:test"); beforeEach(() => { global.gc(); }); afterEach(() => { global.gc(); }); for (let i = 1; i <= 11; ++i) { test(`${i}`, () => { global.gc(); }); } it still log that: also when doing this it had the same effect: function stopTest(timeout, signal) { return new Promise((resolve) => { signal.addEventListener('abort', resolve, { [kWeakHandler]: {} }); setImmediate(() => { global.gc() }).unref() }); } Maybe I'm missing something? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
@rluvaton if we want to keep using the original signal we could keep updating |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
The problem is that we are not cleaning up the abort listener (see that it still happening even when we GC manually) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
The reason why the warning still printed was because of #48951 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Due to fact, #48877 didn't land cleanly on v20.x-staging. This PR somehow, depends on it. So we'll need a manual backport. Reference: https://github.com/nodejs/node/blob/main/doc/contributing/backporting-to-release-lines.md |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Backport PR: |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
fix nodejs#48475 PR-URL: nodejs#48915 Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Chemi Atlow <[email protected]>
no longer needed after nodejs#48915 fix PR-URL: nodejs#48989 Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Chemi Atlow <[email protected]>
fix #48475 PR-URL: #48915 Backport-PR-URL: #49225 Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Chemi Atlow <[email protected]>
no longer needed after #48915 fix PR-URL: #48989 Backport-PR-URL: #49225 Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Chemi Atlow <[email protected]>
There is an `if` statement that likely should have been an `else` in the original PR. Refs: nodejs#48915
There is an `if` statement that likely should have been an `else` in the original PR. Refs: #48915 PR-URL: #49943 Reviewed-By: Chemi Atlow <[email protected]> Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Raz Luvaton <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: LiviaMedeiros <[email protected]>
There is an `if` statement that likely should have been an `else` in the original PR. Refs: #48915 PR-URL: #49943 Reviewed-By: Chemi Atlow <[email protected]> Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Raz Luvaton <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: LiviaMedeiros <[email protected]>
fix #48475 PR-URL: #48915 Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Chemi Atlow <[email protected]>
no longer needed after #48915 fix PR-URL: #48989 Backport-PR-URL: #49225 Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Chemi Atlow <[email protected]>
There is an `if` statement that likely should have been an `else` in the original PR. Refs: #48915 PR-URL: #49943 Reviewed-By: Chemi Atlow <[email protected]> Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Raz Luvaton <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: LiviaMedeiros <[email protected]>
There is an `if` statement that likely should have been an `else` in the original PR. Refs: nodejs#48915 PR-URL: nodejs#49943 Reviewed-By: Chemi Atlow <[email protected]> Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Raz Luvaton <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: LiviaMedeiros <[email protected]>
fix #48475 PR-URL: nodejs/node#48915 Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Chemi Atlow <[email protected]>
There is an `if` statement that likely should have been an `else` in the original PR. Refs: nodejs/node#48915 PR-URL: nodejs/node#49943 Reviewed-By: Chemi Atlow <[email protected]> Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Raz Luvaton <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: LiviaMedeiros <[email protected]>
fix #48475 PR-URL: nodejs/node#48915 Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Chemi Atlow <[email protected]>
There is an `if` statement that likely should have been an `else` in the original PR. Refs: nodejs/node#48915 PR-URL: nodejs/node#49943 Reviewed-By: Chemi Atlow <[email protected]> Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Raz Luvaton <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: LiviaMedeiros <[email protected]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
node:test beforeEach and afterEach generate MaxListenersExceededWarning
There was an error while loading. Please reload this page.