From 82181bb9b8a9861d9b69c2a6aeda454226e0f447 Mon Sep 17 00:00:00 2001 From: Darshan Sen Date: Tue, 15 Mar 2022 00:03:09 +0530 Subject: [PATCH] test: fix failure in test/sequential/test-heapdump.js The test was failing when it was being run with superuser privileges, so this changes the test from attempting to write to a read-only file to attempting to write to a file with the same name as that of an existing directory, as that is a more reliable way of making v8.writeHeapSnapshot() throw even when run with sudo. Fixes: https://github.com/nodejs/node/issues/41643 Signed-off-by: Darshan Sen PR-URL: https://github.com/nodejs/node/pull/41772 Reviewed-By: Antoine du Hamel --- test/sequential/test-heapdump.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/sequential/test-heapdump.js b/test/sequential/test-heapdump.js index e18c6189332574..9b45aa41992fd1 100644 --- a/test/sequential/test-heapdump.js +++ b/test/sequential/test-heapdump.js @@ -25,13 +25,15 @@ process.chdir(tmpdir.path); } { - const readonlyFile = 'ro'; - fs.writeFileSync(readonlyFile, Buffer.alloc(0), { mode: 0o444 }); + const directory = 'directory'; + fs.mkdirSync(directory); assert.throws(() => { - writeHeapSnapshot(readonlyFile); + writeHeapSnapshot(directory); }, (e) => { assert.ok(e, 'writeHeapSnapshot should error'); - assert.strictEqual(e.code, 'EACCES'); + // TODO(RaisinTen): This should throw EISDIR on Windows too. + assert.strictEqual(e.code, + process.platform === 'win32' ? 'EACCES' : 'EISDIR'); assert.strictEqual(e.syscall, 'open'); return true; });