0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/sequential/test-fs-readfile-tostring-fail.js
Rich Trott d3eca02576 test: move resource intensive test to sequential
test-fs-readfile-tostring-fail is resource-intensive and is flaky in
CI. Move to sequential tests so it is not competing for resources with
other tests.

PR-URL: https://github.com/nodejs/node/pull/10744
Fixes: https://github.com/nodejs/node/issues/10742
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2017-01-11 17:18:13 -08:00

61 lines
1.3 KiB
JavaScript

'use strict';
const common = require('../common');
if (!common.enoughTestMem) {
const skipMessage = 'intensive toString tests due to memory confinements';
common.skip(skipMessage);
return;
}
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const kStringMaxLength = process.binding('buffer').kStringMaxLength;
common.refreshTmpDir();
const file = path.join(common.tmpDir, 'toobig.txt');
const stream = fs.createWriteStream(file, {
flags: 'a'
});
const size = kStringMaxLength / 200;
const a = Buffer.alloc(size, 'a');
for (let i = 0; i < 201; i++) {
stream.write(a);
}
stream.end();
stream.on('finish', common.mustCall(function() {
// make sure that the toString does not throw an error
fs.readFile(file, 'utf8', common.mustCall(function(err, buf) {
assert.ok(err instanceof Error);
assert.strictEqual('"toString()" failed', err.message);
assert.strictEqual(buf, undefined);
}));
}));
function destroy() {
try {
fs.unlinkSync(file);
} catch (err) {
// it may not exist
}
}
process.on('exit', destroy);
process.on('SIGINT', function() {
destroy();
process.exit();
});
// To make sure we don't leave a very large file
// on test machines in the event this test fails.
process.on('uncaughtException', function(err) {
destroy();
throw err;
});