-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
test: fix test-repl-import-referrer flakiness #58014
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: fix test-repl-import-referrer flakiness #58014
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #58014 +/- ##
==========================================
- Coverage 90.27% 90.26% -0.01%
==========================================
Files 630 630
Lines 186158 186158
Branches 36475 36474 -1
==========================================
- Hits 168047 168031 -16
- Misses 10980 10988 +8
- Partials 7131 7139 +8 🚀 New features to boost your workflow:
|
setTimeout(() => { | ||
child.stdin.write('await import(\'./message.mjs\');\n'); | ||
child.stdin.write('.exit'); | ||
}, 250); |
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 250? Did you try other values? Could we use a lower one? We should probably be using common.platformTimeout()
btw
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 250? Did you try other values? Could we use a lower one?
250 is totally arbitrary 😓 , I did try different values, 100
seems to be working fine on my
machine but I increased the value as I think a bigger delay would probably be needed in CI
would you prefer me to put 100
instead and see how this performs in CI?
We should probably be using common.platformTimeout() btw
ah yeah for sure, sorry I forgot about this 😓
The following patch seems to fix the issue on my machine. diff --git a/test/parallel/test-repl-import-referrer.js b/test/parallel/test-repl-import-referrer.js
index 9c3e961e5e1..57aae7858ab 100644
--- a/test/parallel/test-repl-import-referrer.js
+++ b/test/parallel/test-repl-import-referrer.js
@@ -8,23 +8,24 @@ const args = ['--interactive'];
const opts = { cwd: fixtures.path('es-modules') };
const child = cp.spawn(process.execPath, args, opts);
-const outputs = [];
+let output = '';
child.stdout.setEncoding('utf8');
child.stdout.on('data', (data) => {
- outputs.push(data);
- if (outputs.length === 3) {
+ output += data;
+
+ if (
+ !child.stdin.writableEnded &&
+ output.includes('[Module: null prototype] { message: \'A message\' }')
+ ) {
// All the expected outputs have been received
// so we can close the child process's stdin
child.stdin.end();
}
});
-child.on('exit', common.mustCall(() => {
- const results = outputs[2].split('\n')[0];
- assert.strictEqual(
- results,
- '[Module: null prototype] { message: \'A message\' }'
- );
+child.on('exit', common.mustCall((code, signal) => {
+ assert.strictEqual(code, 0);
+ assert.strictEqual(signal, null);
}));
child.stdin.write('await import(\'./message.mjs\');\n');
|
Thanks a lot @lpinca 🙂 Checking for the output string in the on data listener is something that occurred to me too, but I don't attempt to go that route as I think it doesn't leads to nice patterns here 😕 😓 In your suggested solution specifically I have concerns about the readability of the test, using Anyways if you strongly believe that your suggested solution is better (I'd also be curious to see other opinions on it hopefully) I am totally fine to go with it, as using |
What is the difference? Currently it is based on counting data chunks which is not reliable. I definitely think it is way better than adding a random delay. Timers are known to cause flakiness. |
The main difference I see is that we're not directly asserting that the string is in the output which is the whole point of the test 😖
Is it not? how come? isn't that deterministic? 😮
yeah I think that this is a very fair point of view 👍 |
We do, if there isn't the test times out. |
yes, of course we do, I was saying that it's not being done in a direct way (there is not this in my opinion reduces readability and it might make the issue more difficult to diagnose since the failure would be a timeout instead of an assert failure (although someone could argue that given the current flakes that's almost already the case 😓) |
There are hundreds of tests like this.
Here is an example when test currently fails found by applying this patch diff --git a/test/parallel/test-repl-import-referrer.js b/test/parallel/test-repl-import-referrer.js
index 9c3e961e5e1..41204efda17 100644
--- a/test/parallel/test-repl-import-referrer.js
+++ b/test/parallel/test-repl-import-referrer.js
@@ -12,6 +12,7 @@ const outputs = [];
child.stdout.setEncoding('utf8');
child.stdout.on('data', (data) => {
outputs.push(data);
+ console.log(outputs)
if (outputs.length === 3) {
// All the expected outputs have been received
// so we can close the child process's stdin
As you can see there are only 2 chunks, the test waits for 3 before calling |
Co-authored-by: Luigi Pinca <[email protected]>
c8c1e6c
to
7f7cea4
Compare
👍
ah ok, sorry I thought that the chunking would be pretty stable/deterministic (I guess it is on the same machine?), thanks for pointing this 🙏 |
Thanks a lot for the suggested change @lpinca 🙏, I've applied it 🙂 |
Stress test CI: https://ci.nodejs.org/job/node-stress-single-test/564/ |
Co-authored-by: Luigi Pinca <[email protected]>
I was thinking of a simpler fix with fewer changes than the original test diff --git a/test/parallel/test-repl-import-referrer.js b/test/parallel/test-repl-import-referrer.js
index 9c3e961e5e1..c1b82198a25 100644
--- a/test/parallel/test-repl-import-referrer.js
+++ b/test/parallel/test-repl-import-referrer.js
@@ -8,24 +8,19 @@ const args = ['--interactive'];
const opts = { cwd: fixtures.path('es-modules') };
const child = cp.spawn(process.execPath, args, opts);
-const outputs = [];
+let output = '';
child.stdout.setEncoding('utf8');
child.stdout.on('data', (data) => {
- outputs.push(data);
- if (outputs.length === 3) {
- // All the expected outputs have been received
- // so we can close the child process's stdin
- child.stdin.end();
- }
+ output += data;
});
child.on('exit', common.mustCall(() => {
- const results = outputs[2].split('\n')[0];
- assert.strictEqual(
- results,
- '[Module: null prototype] { message: \'A message\' }'
- );
+ const results = output.replace(/^> /mg, '').split('\n').slice(2);
+ assert.deepStrictEqual(results, [
+ '[Module: null prototype] { message: \'A message\' }',
+ ''
+ ]);
}));
child.stdin.write('await import(\'./message.mjs\');\n');
-child.stdin.write('.exit');
+child.stdin.write('.exit\n');
but it fails as an |
No, for sure this is not expected... and I would imagine it to indeed most likely be an unwanted effect of 8e7f32f, the fact that you see the error without manually closing the child's I'll have a look as soon as I can (later today/tomorrow), I wonder if this is so severe that 8e7f32f should be reverted 😖 |
Co-authored-by: Luigi Pinca <[email protected]>
I was thinking the same thing. |
Co-authored-by: Luigi Pinca <[email protected]>
I'm happy to investigate this, but if we're concerned about user's impact it could be safer to revert sooner rather than later... since #57680 was marked as semver-major can I assume that only users using node 25 (when it will come out) would potentially be affected? |
Yes, there are also nightly builds, but I don't expect people to use them in production 😄. FWIW, I can also reproduce it manually
|
@lpinca yes I can as well! 😓 ok this is pretty bad... (I'm surprised that no tests consistently failed because of this 😓) maybe I should close this PR and revert 8e7f32f right away to be on the safe side, then try to reintroduce the change but also making sure that there's no repl error being thrown... what do you think? 😓 (PS: I'm really sorry for the inconvenience caused here, I'm really surprised that something like this managed to sneak through 😓) |
I think it makes sense.
No problem, it happens. |
Closing in favour of #58024 |
Fixes #58009