-
Notifications
You must be signed in to change notification settings - Fork 30k
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: add stream map tests #41642
test: add stream map tests #41642
Conversation
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.
lgtm
const stream = Readable.from([1, 2, 3, 4, 5]).map(async (x) => { | ||
if (x === 3) { | ||
stream.emit('error', new Error('boom')); | ||
} | ||
return x + x; | ||
}); | ||
assert.rejects( | ||
stream.map((x) => x + x).toArray(), | ||
/boom/, |
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.
We could check the error by reference here and below.
const stream = Readable.from([1, 2, 3, 4, 5]).map(async (x) => { | |
if (x === 3) { | |
stream.emit('error', new Error('boom')); | |
} | |
return x + x; | |
}); | |
assert.rejects( | |
stream.map((x) => x + x).toArray(), | |
/boom/, | |
const error = new Error(); | |
const stream = Readable.from([1, 2, 3, 4, 5]).map(async (x) => { | |
if (x === 3) { | |
stream.emit('error', error); | |
} | |
return x + x; | |
}); | |
assert.rejects( | |
stream.map((x) => x + x).toArray(), | |
error, |
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'm not sure that's actually a guarantee we necessarily want to make in this case (that is - that if we emit we don't wrap the error in any way) - the guarantee currently tested is much smaller (that we include the message).
If you feel strongly it's a guarantee we should make - I'll change it (we should also probably update the docs)
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.
If the current implementation does reject with the same error object, and in the future we decide to wrap this object in some other object, wouldn't you agree this would be a semver-major change? That's why I would say testing for it would make sense.
The proposal says we should Await
at each step, so I would think that implies the same rejected object is returned. Maybe we should make another test that verifies that when using a non-Error
objects, everything still behaves. Non-blocking suggestion.
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.
wouldn't you agree this would be a semver-major change?
Not on an experimental API - once it graduates 100% absolutely.
The proposal says we should Await at each step, so I would think that implies the same rejected object is returned.
Yes but note that in this case the user is explicitly emit
ing the error event rather than throwing an error - I agree that for throwing we 100% should align.
Non-blocking suggestion.
Please keep making suggestions discussing these things is important!
(async () => { | ||
assert.deepStrictEqual(await stream.toArray(), [2, 4, 6, 8, 10]); | ||
})().then(common.mustCall()); |
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.
It might be sound to consider using a .mjs
file for future tests like this so we can use TLA and skip all those async functions + then(mustCall).
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 was wondering if that was allowed but couldn’t find non-loader related .mjs tests. If it is I think it’s a good idea
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.
@aduh95 so can you confirm it's allowed :)? I'll port the file to .mjs
I don't mind the tests running sequentially that'd actually make things easier to debug and the performance won't change since it's all microticks anyway.
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.
Nothing forbids it, so it's allowed (and there's no reason to avoid it since Node.js 10 is EOL and all maintained versions of Node.js support ESM). For example see test/parallel/test-child-process-fork-url.mjs
and test/parallel/test-fs-cp.mjs
which have little to do with loaders and have been written this way because it was more convenient.
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.
Ack I'll move all of these to mjs and simplify them as soon as the two PRs by outside contributors land to not create conflicts for them.
@benjamingr we should probably fix this flaky test (failing on node-test-binary-arm-12+):
|
|
The failing test doesn't seem to use timers at all - {
// Map works on non-objectMode streams
const stream = new Readable({
read() {
this.push(Uint8Array.from([1]));
this.push(Uint8Array.from([2]));
this.push(null);
}
}).map(async ([x]) => {
return x + x;
}).map((x) => x + x);
const result = [4, 8];
(async () => {
for await (const item of stream) {
assert.strictEqual(item, result.shift());
}
})().then(common.mustCall());
} That's the one that's flakey on arm if I understand correctly right? |
It's this one: node/test/parallel/test-stream-map.js Lines 49 to 69 in b97b81d
The test is flaky on |
Ah phew that's much much better and a way less severe bug. I'll push a fix. |
Add more tests to check and enforce the behavior of the map method. Co-Authored-By: Antoine du Hamel <[email protected]>
I'm giving you Co-Authored-By on the commit @aduh95 for the feedback and help. If you prefer otherwise let me know. |
4851448
to
a5d1087
Compare
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.
Let's land this!
Commit Queue failed- Loading data for nodejs/node/pull/41642 ✔ Done loading data for nodejs/node/pull/41642 ----------------------------------- PR info ------------------------------------ Title test: add stream map tests (#41642) Author Benjamin Gruenbaum (@benjamingr) Branch benjamingr:stream-map-improve-coverage -> nodejs:master Labels test, author ready, needs-ci Commits 1 - test: add stream map tests Committers 1 - Benjamin Gruenbaum PR-URL: https://github.com/nodejs/node/pull/41642 Reviewed-By: Matteo Collina Reviewed-By: Robert Nagy Reviewed-By: Antoine du Hamel ------------------------------ Generated metadata ------------------------------ PR-URL: https://github.com/nodejs/node/pull/41642 Reviewed-By: Matteo Collina Reviewed-By: Robert Nagy Reviewed-By: Antoine du Hamel -------------------------------------------------------------------------------- ℹ This PR was created on Sat, 22 Jan 2022 08:26:46 GMT ✔ Approvals: 3 ✔ - Matteo Collina (@mcollina) (TSC): https://github.com/nodejs/node/pull/41642#pullrequestreview-860186327 ✔ - Robert Nagy (@ronag) (TSC): https://github.com/nodejs/node/pull/41642#pullrequestreview-860186417 ✔ - Antoine du Hamel (@aduh95) (TSC): https://github.com/nodejs/node/pull/41642#pullrequestreview-861240334 ✔ Last GitHub CI successful ℹ Last Full PR CI on 2022-01-24T15:01:39Z: https://ci.nodejs.org/job/node-test-pull-request/42121/ - Querying data for job/node-test-pull-request/42121/ ✔ Last Jenkins CI successful -------------------------------------------------------------------------------- ✔ No git cherry-pick in progress ✔ No git am in progress ✔ No git rebase in progress -------------------------------------------------------------------------------- - Bringing origin/master up to date... From https://github.com/nodejs/node * branch master -> FETCH_HEAD ✔ origin/master is now up-to-date - Downloading patch for 41642 From https://github.com/nodejs/node * branch refs/pull/41642/merge -> FETCH_HEAD ✔ Fetched commits as 3ee8c3e45e5f..a5d10870149e -------------------------------------------------------------------------------- [master e621b51bb8] test: add stream map tests Author: Benjamin Gruenbaum Date: Sat Jan 22 10:25:18 2022 +0200 1 file changed, 105 insertions(+), 16 deletions(-) ✔ Patches applied -------------------------------------------------------------------------------- --------------------------------- New Message ---------------------------------- test: add stream map testshttps://github.com/nodejs/node/actions/runs/1741370378 |
Add more tests to check and enforce the behavior of the map method. Co-Authored-By: Antoine du Hamel <[email protected]> PR-URL: #41642 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
Landed in Landed in ce41395 🎉 |
Add more tests to check and enforce the behavior of the map method. Co-Authored-By: Antoine du Hamel <[email protected]> PR-URL: nodejs#41642 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
Add more tests to check and enforce the behavior of the map method. Co-Authored-By: Antoine du Hamel <[email protected]> PR-URL: #41642 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
@benjamingr do you mind backporting these to v16.x? They break when backporting as is. |
@danielleadams I don't think these need backporting they test a feature that doesn't exist on v16.x - let me add the labels |
Adds more tests to cover more cases of
map
namely that it works on infinite streams and the error handling behavior. Most other methods also need these sort of tests.cc @nodejs/streams @aduh95