2015-10-22 13:58:26 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const common = require('../common');
|
2016-07-17 18:33:35 +02:00
|
|
|
|
|
|
|
if (!common.enoughTestMem) {
|
|
|
|
const skipMessage = 'intensive toString tests due to memory confinements';
|
|
|
|
common.skip(skipMessage);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-22 13:58:26 +02:00
|
|
|
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;
|
2016-01-26 00:00:06 +01:00
|
|
|
const a = Buffer.alloc(size, 'a');
|
2015-10-22 13:58:26 +02:00
|
|
|
|
|
|
|
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);
|
2015-11-10 00:10:49 +01:00
|
|
|
assert.strictEqual('"toString()" failed', err.message);
|
2016-11-18 04:03:39 +01:00
|
|
|
assert.strictEqual(buf, undefined);
|
2015-10-22 13:58:26 +02:00
|
|
|
}));
|
|
|
|
}));
|
|
|
|
|
|
|
|
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;
|
|
|
|
});
|