Skip to content
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

Allow manipulating the generator in Duplex.from() #55096

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

matthieusieben
Copy link
Contributor

Fix for #55077

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. test Issues and PRs related to the tests. labels Sep 24, 2024
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm with a few nits, good job

return end(err).then(originalThrow.bind(this, err));
};


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove this empty line


// Not using try/finally because asyncGenerator.return() should work even
// if the generator was never started.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you attach this comment to the section it refers to?

@mcollina mcollina requested a review from ronag September 24, 2024 11:12
@mcollina mcollina added the request-ci Add this label to start a Jenkins CI on a PR. label Sep 24, 2024
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Sep 24, 2024
@nodejs-github-bot
Copy link
Collaborator

}

{
const r = Readable.from(['foo', 'bar', 'bar']);
Copy link
Member

@RedYetiDev RedYetiDev Sep 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const r = Readable.from(['foo', 'bar', 'bar']);
const r = Readable.from(['foo', 'bar', 'baz']);

(for consistency)

Comment on lines 407 to 412
const r = Readable.from(['foo', 'bar', 'bar']);
pipeline(
r,
Duplex.from(async function(asyncGenerator) {
const values = await Array.fromAsync(asyncGenerator);
assert.deepStrictEqual(values, ['foo', 'bar', 'bar']);
Copy link
Member

@RedYetiDev RedYetiDev Sep 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const r = Readable.from(['foo', 'bar', 'bar']);
pipeline(
r,
Duplex.from(async function(asyncGenerator) {
const values = await Array.fromAsync(asyncGenerator);
assert.deepStrictEqual(values, ['foo', 'bar', 'bar']);
const r = Readable.from(['foo', 'bar', 'baz']);
pipeline(
r,
Duplex.from(async function(asyncGenerator) {
const values = await Array.fromAsync(asyncGenerator);
assert.deepStrictEqual(values, ['foo', 'bar', 'baz']);

(for consistency)

let d;

const { value, write, final, destroy } = fromAsyncGen(body, () => {
if (d) destroyer(d);
Copy link
Member

@RedYetiDev RedYetiDev Sep 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (d) destroyer(d);
destroyer(d);

The destroyer function already checks whether the stream exists:

if (!stream || isDestroyed(stream)) {

const promise = FunctionPrototypeCall(
then,
value,
(val) => {
destroyer(d, null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
destroyer(d, null);
destroyer(d);

If err is null, it's treated the same as if it's undefined:

if (!err && !isFinished(stream)) {

@RedYetiDev RedYetiDev added the stream Issues and PRs related to the stream subsystem. label Sep 24, 2024
@matthieusieben
Copy link
Contributor Author

Not sure what is wrong with the tests that are not passing:

=== release test-stream-compose ===
Path: parallel/test-stream-compose
/Users/msi/Github/nodejs/node/test/parallel/test-stream-compose.js:401
    assert.strictEqual(err.code, 'ERR_INVALID_RETURN_VALUE');
                           ^

TypeError: Cannot read properties of undefined (reading 'code')
    at Duplex.<anonymous> (/Users/msi/Github/nodejs/node/test/parallel/test-stream-compose.js:401:28)
    at Duplex.<anonymous> (/Users/msi/Github/nodejs/node/test/common/index.js:493:15)
    at Duplex.<anonymous> (node:internal/util:546:20)
    at Duplex.onclose (node:internal/streams/end-of-stream:161:14)
    at Duplex.emit (node:events:507:28)
    at emitCloseNT (node:internal/streams/destroy:148:10)
    at process.processTicksAndRejections (node:internal/process/task_queues:89:21)

Node.js v23.0.0-pre
Command: out/Release/node --expose-internals /Users/msi/Github/nodejs/node/test/parallel/test-stream-compose.js
=== release test-stream-compose-operator ===
Path: parallel/test-stream-compose-operator
node:internal/process/promises:394
    triggerUncaughtException(err, true /* fromPromise */);
    ^

AssertionError [ERR_ASSERTION]: The input did not match the regular expression /boom/. Input:

'AbortError: The operation was aborted'

    at process.processTicksAndRejections (node:internal/process/task_queues:105:5) {
  generatedMessage: true,
  code: 'ERR_ASSERTION',
  actual: AbortError: The operation was aborted
      at destroyer (node:internal/streams/destroy:328:11)
      at node:internal/streams/duplexify:89:7
      at asyncGenerator.return (node:internal/streams/duplexify:245:9)
      at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
      at async /Users/msi/Github/nodejs/node/test/parallel/test-stream-compose-operator.js:63:5
      at async nextAsync (node:internal/streams/from:182:33) {
    code: 'ABORT_ERR'
  },
  expected: /boom/,
  operator: 'rejects'
}

Node.js v23.0.0-pre
Command: out/Release/node /Users/msi/Github/nodejs/node/test/parallel/test-stream-compose-operator.js

Copy link

codecov bot commented Sep 24, 2024

Codecov Report

Attention: Patch coverage is 96.36364% with 2 lines in your changes missing coverage. Please review.

Project coverage is 88.24%. Comparing base (3c5ceff) to head (12439c6).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
lib/internal/streams/duplexify.js 96.36% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #55096      +/-   ##
==========================================
- Coverage   88.24%   88.24%   -0.01%     
==========================================
  Files         651      651              
  Lines      183877   183925      +48     
  Branches    35858    35866       +8     
==========================================
+ Hits       162266   162307      +41     
+ Misses      14901    14899       -2     
- Partials     6710     6719       +9     
Files with missing lines Coverage Δ
lib/internal/streams/duplexify.js 96.48% <96.36%> (-0.09%) ⬇️

... and 32 files with indirect coverage changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-ci PRs that need a full CI run. stream Issues and PRs related to the stream subsystem. test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants