0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-worker-stdio.js
Adam Majer 001da4d088
test: reduce memory usage of test-worker-stdio
On systems with limited memory and that are compiled with debugging
information, this particular test is causing OOM condition
especially as it is run in parallel. Even when run with a stripped
binary as an input, the test consumes upward of 250M RSS. By
limiting the input stream to the 1M, the stream is still buffering
but memory consumption is similar to other parallel tests.

PR-URL: https://github.com/nodejs/node/pull/37769
Reviewed-By: Michael Dawson <midawson@redhat.com>
2024-05-10 19:31:20 +02:00

43 lines
1.1 KiB
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const fs = require('fs');
const util = require('util');
const { Writable } = require('stream');
const { Worker, isMainThread } = require('worker_threads');
class BufferingWritable extends Writable {
constructor() {
super();
this.chunks = [];
}
_write(chunk, enc, cb) {
this.chunks.push(chunk);
cb();
}
get buffer() {
return Buffer.concat(this.chunks);
}
}
if (isMainThread) {
const original = new BufferingWritable();
const passed = new BufferingWritable();
const w = new Worker(__filename, { stdin: true, stdout: true });
const source = fs.createReadStream(process.execPath, { end: 1_000_000 });
source.pipe(w.stdin);
source.pipe(original);
w.stdout.pipe(passed);
passed.on('finish', common.mustCall(() => {
assert.strictEqual(original.buffer.compare(passed.buffer), 0,
`Original: ${util.inspect(original.buffer)}, ` +
`Actual: ${util.inspect(passed.buffer)}`);
}));
} else {
process.stdin.pipe(process.stdout);
}