Skip to content

Commit 5402670

Browse files
committed
UT
1 parent 3b84bfb commit 5402670

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

lib/internal/fs/streams.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ function writeAll(data, size, pos, cb, retries = 0) {
415415
if (retries > 5) {
416416
cb(new ERR_SYSTEM_ERROR('write failed'));
417417
} else if (size) {
418-
writeAll(buffer.slice(bytesWritten), size, pos, cb, retries);
418+
writeAll.call(this, buffer.slice(bytesWritten), size, pos, cb, retries);
419419
} else {
420420
cb();
421421
}
@@ -444,7 +444,7 @@ function writevAll(chunks, size, pos, cb, retries = 0) {
444444
if (retries > 5) {
445445
cb(new ERR_SYSTEM_ERROR('writev failed'));
446446
} else if (size) {
447-
writevAll([Buffer.concat(buffers).slice(bytesWritten)], size, pos, cb, retries);
447+
writevAll.call(this, [Buffer.concat(buffers).slice(bytesWritten)], size, pos, cb, retries);
448448
} else {
449449
cb();
450450
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import * as common from '../common/index.mjs';
2+
import tmpdir from '../common/tmpdir.js';
3+
import assert from 'node:assert';
4+
import fs from 'node:fs';
5+
import { describe, it, mock } from 'node:test';
6+
import { finished } from 'node:stream/promises';
7+
8+
const file = tmpdir.resolve('writeStreamEAGAIN.txt');
9+
const errorWithEAGAIN = (fd, buffer, offset, length, position, callback) => {
10+
callback(Object.assign(new Error(), { code: 'EAGAIN' }), 0, buffer);
11+
}
12+
13+
describe('WriteStream EAGAIN', { concurrency: true }, () => {
14+
it('_write', async () => {
15+
const mockWrite = mock.fn(fs.write);
16+
mockWrite.mock.mockImplementationOnce(errorWithEAGAIN);
17+
const stream = fs.createWriteStream(file, {
18+
fs: {
19+
open: common.mustCall(fs.open),
20+
write: mockWrite,
21+
close: common.mustCall(fs.close),
22+
}
23+
});
24+
stream.end('foo');
25+
stream.on('close', common.mustCall());
26+
stream.on('error', common.mustNotCall());
27+
await finished(stream);
28+
assert.strictEqual(mockWrite.mock.callCount(), 2);
29+
assert.strictEqual(fs.readFileSync(file, 'utf8'), 'foo');
30+
});
31+
});

0 commit comments

Comments
 (0)