node/test/parallel/test-worker-stdio-from-preload-module.js
Robert Nagy fadb214d95
stream: readable read one buffer at a time
Instead of wasting cycles concatenating buffers, just return each
one by one.

Similar (but not exact) old behavior can be achieved by using
`readable.read(readable.readableLength)` instead of
`readable.read()`. In some edge cases it might be necessary
to do a `readable.read(0)` first.

PR: https://github.com/nodejs/node/pull/60441
PR-URL: https://github.com/nodejs/node/pull/60441
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
2026-01-21 08:29:40 +00:00

20 lines
696 B
JavaScript

'use strict';
const common = require('../common');
const fixtures = require('../common/fixtures');
const { Worker } = require('worker_threads');
const assert = require('assert');
// Regression test for https://github.com/nodejs/node/issues/31777:
// stdio operations coming from preload modules should count towards the
// ref count of the internal communication port on the Worker side.
for (let i = 0; i < 10; i++) {
const w = new Worker('console.log("B");', {
execArgv: ['--require', fixtures.path('printA.js')],
eval: true,
stdout: true
});
w.on('exit', common.mustCall(() => {
assert.strictEqual(w.stdout.read(w.stdout.readableLength).toString(), 'A\nB\n');
}));
}