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

test: add mustCall() to child-process test #13605

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions test/parallel/test-child-process-stdio-big-write-end.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';
require('../common');
const common = require('../common');
const assert = require('assert');
const BUFSIZE = 1024;

Expand All @@ -43,10 +43,10 @@ function parent() {
child.stdout.on('data', function(c) {
Copy link
Contributor

Choose a reason for hiding this comment

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

How about adding a mustCallAtLeast?
(I see that the value of n is asserted, but this will give a one-step-closer-to-root-cause assertion error)

Copy link
Member Author

Choose a reason for hiding this comment

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

If I understand correctly, the assertion on n will occur before any assertion by mustCallAtLeast().

Copy link
Contributor

Choose a reason for hiding this comment

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

Ack.

n += c;
});
child.stdout.on('end', function() {
child.stdout.on('end', common.mustCall(function() {
assert.strictEqual(+n, sent);
Copy link
Contributor

Choose a reason for hiding this comment

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

the + is cheating the strict
either put on the right side send + '\n' ('\n' is because data comes from console.log)
or replace the 'data' handler with:

  let n = 0;
  child.stdout.setEncoding('ascii');
  child.stdout.on('data', function(d) {
    const c = Number(d);
    if (!c) assert.fail(c);
    n += c;
  });

console.log('ok');
Copy link
Contributor

Choose a reason for hiding this comment

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

Should remove (maybe replace with comment // end of test)

});
}));

// Write until the buffer fills up.
let buf;
Expand Down