Skip to content

Commit

Permalink
test: replace flaky pummel regression tests
Browse files Browse the repository at this point in the history
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: nodejs#34527

PR-URL: nodejs#34530
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Andrey Pechkurov <[email protected]>
Reviewed-By: Jiawen Geng <[email protected]>
  • Loading branch information
addaleax authored and gengjiawen committed Aug 4, 2020
1 parent 74df749 commit 0bb70b0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 195 deletions.
39 changes: 39 additions & 0 deletions test/parallel/test-fs-write-reuse-callback.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Flags: --expose-gc
'use strict';
const common = require('../common');
const tmpdir = require('../common/tmpdir');
const assert = require('assert');
const path = require('path');

// Regression test for https://github.com/nodejs/node-v0.x-archive/issues/814:
// Make sure that Buffers passed to fs.write() are not garbage-collected
// even when the callback is being reused.

const fs = require('fs');

tmpdir.refresh();
const filename = path.join(tmpdir.path, 'test.txt');
const fd = fs.openSync(filename, 'w');

const size = 16 * 1024;
const writes = 1000;
let done = 0;

const ondone = common.mustCall((err) => {
assert.ifError(err);
if (++done < writes) {
if (done % 25 === 0) global.gc();
setImmediate(write);
} else {
assert.strictEqual(
fs.readFileSync(filename, 'utf8'),
'x'.repeat(writes * size));
fs.closeSync(fd);
}
}, writes);

write();
function write() {
const buf = Buffer.alloc(size, 'x');
fs.write(fd, buf, 0, buf.size, -1, ondone);
}
90 changes: 0 additions & 90 deletions test/pummel/test-regress-GH-814.js

This file was deleted.

105 changes: 0 additions & 105 deletions test/pummel/test-regress-GH-814_2.js

This file was deleted.

0 comments on commit 0bb70b0

Please sign in to comment.