node/test/parallel/test-fs-stream-construct-compat-error-write.js
Rich Trott 772fdb0cd3 test: fix flaky test-fs-stream-construct
The test is marked flaky on ARM because it times out on Raspberry Pi
devices in CI. Split the single test file into four separate test files
to ease debugging. Add fs.close() to avoid timing out.

Fixes: https://github.com/nodejs/node/issues/33796

PR-URL: https://github.com/nodejs/node/pull/34203
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
2020-07-06 17:32:24 -07:00

51 lines
1.4 KiB
JavaScript

'use strict';
const common = require('../common');
const fs = require('fs');
const assert = require('assert');
const debuglog = (arg) => {
console.log(new Date().toLocaleString(), arg);
};
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
{
// Compat error.
debuglog('start test');
function WriteStream(...args) {
debuglog('WriteStream constructor');
fs.WriteStream.call(this, ...args);
}
Object.setPrototypeOf(WriteStream.prototype, fs.WriteStream.prototype);
Object.setPrototypeOf(WriteStream, fs.WriteStream);
WriteStream.prototype.open = common.mustCall(function WriteStream$open() {
debuglog('WriteStream open() callback');
const that = this;
fs.open(that.path, that.flags, that.mode, (err, fd) => {
debuglog('inner fs open() callback');
that.emit('error', err);
});
});
fs.open(`${tmpdir.path}/dummy`, 'wx+', common.mustCall((err, fd) => {
debuglog('fs open() callback');
assert.ifError(err);
fs.close(fd, () => { debuglog(`closed ${fd}`); });
const w = new WriteStream(`${tmpdir.path}/dummy`,
{ flags: 'wx+', emitClose: true })
.on('error', common.mustCall((err) => {
debuglog('error event callback');
assert.strictEqual(err.code, 'EEXIST');
w.destroy();
w.on('close', common.mustCall(() => {
debuglog('close event callback');
}));
}));
}));
debuglog('waiting for callbacks');
}