0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-fs-readfile-tostring-fail.js
Rich Trott 135a863f80 test: increase RAM requirement for intensive tests
test-fs-read-buffer-tostring-fail and test-fs-readfile-tostring-fail
have been timing out on Raspberry Pi 3 devices on the continuous
integration server. These devices have 1 Gb of RAM and the tests are
memory intensive. Previous checks for memory intensive tests used a 512
Mb cut-off, but that was probably instituted when we only had Pi 1
devices.

Consequently, this change increases the threshold for memory-intensive
tests to 1 Gb and adds that threshold to test-fs-readfile-tostring-fail.

PR-URL: https://github.com/nodejs/node/pull/7772
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
2016-07-20 09:55:36 -07:00

60 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 (var 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);
}));
}));
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;
});