mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 21:19:50 +01:00
bae14b7914
Our CI already run test files in parallel, having `node:test` spawns child processes concurrently could lead to oversubscribing the CI machine. This commit sets the `concurrency` depending on the presence of `TEST_PARALLEL` in the env, so running the test file individually still spawns child processes concurrently, and running the whole test suite does not oversubscribe the machine. PR-URL: https://github.com/nodejs/node/pull/52177 Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
40 lines
1.3 KiB
JavaScript
40 lines
1.3 KiB
JavaScript
import * as common from '../common/index.mjs';
|
|
import tmpdir from '../common/tmpdir.js';
|
|
import assert from 'node:assert';
|
|
import fs from 'node:fs';
|
|
import { describe, it, mock } from 'node:test';
|
|
import { finished } from 'node:stream/promises';
|
|
|
|
tmpdir.refresh();
|
|
const file = tmpdir.resolve('writeStreamEAGAIN.txt');
|
|
const errorWithEAGAIN = (fd, buffer, offset, length, position, callback) => {
|
|
callback(Object.assign(new Error(), { code: 'EAGAIN' }), 0, buffer);
|
|
};
|
|
|
|
describe('WriteStream EAGAIN', { concurrency: !process.env.TEST_PARALLEL }, () => {
|
|
it('_write', async () => {
|
|
const mockWrite = mock.fn(fs.write);
|
|
mockWrite.mock.mockImplementationOnce(errorWithEAGAIN);
|
|
const stream = fs.createWriteStream(file, {
|
|
fs: {
|
|
open: common.mustCall(fs.open),
|
|
write: mockWrite,
|
|
close: common.mustCall(fs.close),
|
|
}
|
|
});
|
|
stream.end('foo');
|
|
stream.on('close', common.mustCall());
|
|
stream.on('error', common.mustNotCall());
|
|
await finished(stream);
|
|
assert.strictEqual(mockWrite.mock.callCount(), 2);
|
|
assert.strictEqual(fs.readFileSync(file, 'utf8'), 'foo');
|
|
});
|
|
|
|
it('_write', async () => {
|
|
const stream = fs.createWriteStream(file);
|
|
mock.getter(stream, 'destroyed', () => true);
|
|
stream.end('foo');
|
|
await finished(stream).catch(common.mustCall());
|
|
});
|
|
});
|