Skip to content

Commit 54a4c6a

Browse files
addaleaxcodebytere
authored andcommitted
test: replace flaky pummel regression tests
These tests were written a long time ago, and use the allocation of large amounts of unused memory as a way to detect use-after-free problems with Buffers. As a result, the tests are resource-intensive and may crash because of that. Replace them with a more modern test. We don’t explicitly try to *detect* use-after-free conditions, and instead rely on e.g. ASAN (or the process just crashing hard) to do that for us. Fixes: #34527 PR-URL: #34530 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Andrey Pechkurov <[email protected]> Reviewed-By: Jiawen Geng <[email protected]>
1 parent 12cb0fb commit 54a4c6a

File tree

3 files changed

+39
-195
lines changed

3 files changed

+39
-195
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Flags: --expose-gc
2+
'use strict';
3+
const common = require('../common');
4+
const tmpdir = require('../common/tmpdir');
5+
const assert = require('assert');
6+
const path = require('path');
7+
8+
// Regression test for https://github.com/nodejs/node-v0.x-archive/issues/814:
9+
// Make sure that Buffers passed to fs.write() are not garbage-collected
10+
// even when the callback is being reused.
11+
12+
const fs = require('fs');
13+
14+
tmpdir.refresh();
15+
const filename = path.join(tmpdir.path, 'test.txt');
16+
const fd = fs.openSync(filename, 'w');
17+
18+
const size = 16 * 1024;
19+
const writes = 1000;
20+
let done = 0;
21+
22+
const ondone = common.mustCall((err) => {
23+
assert.ifError(err);
24+
if (++done < writes) {
25+
if (done % 25 === 0) global.gc();
26+
setImmediate(write);
27+
} else {
28+
assert.strictEqual(
29+
fs.readFileSync(filename, 'utf8'),
30+
'x'.repeat(writes * size));
31+
fs.closeSync(fd);
32+
}
33+
}, writes);
34+
35+
write();
36+
function write() {
37+
const buf = Buffer.alloc(size, 'x');
38+
fs.write(fd, buf, 0, buf.size, -1, ondone);
39+
}

test/pummel/test-regress-GH-814.js

-90
This file was deleted.

test/pummel/test-regress-GH-814_2.js

-105
This file was deleted.

0 commit comments

Comments
 (0)