Skip to content

Commit 5b78bf2

Browse files
bnoordhuistargos
authored andcommitted
test: work around ENOTEMPTY when cleaning tmp dir
Replace the homegrown rimrafsync implementation in test/common with a call to `fs.rmdirSync(path, { recursive: true })`. Fixes: #30620 Fixes: #30844 PR-URL: #30849 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent b1358d3 commit 5b78bf2

File tree

5 files changed

+7
-46
lines changed

5 files changed

+7
-46
lines changed

test/async-hooks/test-pipeconnectwrap.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ const { checkInvocations } = require('./hook-checks');
88
const tmpdir = require('../common/tmpdir');
99
const net = require('net');
1010

11-
// Spawning messes up `async_hooks` state.
12-
tmpdir.refresh({ spawn: false });
11+
tmpdir.refresh();
1312

1413
const hooks = initHooks();
1514
hooks.enable();

test/async-hooks/test-statwatcher.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const path = require('path');
1111
if (!common.isMainThread)
1212
common.skip('Worker bootstrapping works differently -> different async IDs');
1313

14-
tmpdir.refresh({ spawn: false });
14+
tmpdir.refresh();
1515

1616
const file1 = path.join(tmpdir.path, 'file1');
1717
const file2 = path.join(tmpdir.path, 'file2');

test/common/README.md

+1-5
Original file line numberDiff line numberDiff line change
@@ -898,11 +898,7 @@ The `tmpdir` module supports the use of a temporary directory for testing.
898898

899899
The realpath of the testing temporary directory.
900900

901-
### refresh(\[opts\])
902-
903-
* `opts` [&lt;Object>][] (optional) Extra options.
904-
* `spawn` [&lt;boolean>][] (default: `true`) Indicates that `refresh` is
905-
allowed to optionally spawn a subprocess.
901+
### refresh()
906902

907903
Deletes and recreates the testing temporary directory.
908904

test/common/tmpdir.js

+4-34
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,11 @@
11
/* eslint-disable node-core/require-common-first, node-core/required-modules */
22
'use strict';
33

4-
const { execSync } = require('child_process');
54
const fs = require('fs');
65
const path = require('path');
7-
const { debuglog } = require('util');
86

9-
const debug = debuglog('test/tmpdir');
10-
11-
function rimrafSync(pathname, { spawn = true } = {}) {
12-
const st = (() => {
13-
try {
14-
return fs.lstatSync(pathname);
15-
} catch (e) {
16-
if (fs.existsSync(pathname))
17-
throw new Error(`Something wonky happened rimrafing ${pathname}`);
18-
debug(e);
19-
}
20-
})();
21-
22-
// If (!st) then nothing to do.
23-
if (!st) {
24-
return;
25-
}
26-
27-
// On Windows first try to delegate rmdir to a shell.
28-
if (spawn && process.platform === 'win32' && st.isDirectory()) {
29-
try {
30-
// Try `rmdir` first.
31-
execSync(`rmdir /q /s ${pathname}`, { timeout: 1000 });
32-
} catch (e) {
33-
// Attempt failed. Log and carry on.
34-
debug(e);
35-
}
36-
}
37-
38-
fs.rmdirSync(pathname, { recursive: true, maxRetries: 5 });
7+
function rimrafSync(pathname) {
8+
fs.rmdirSync(pathname, { maxRetries: 3, recursive: true });
399
}
4010

4111
const testRoot = process.env.NODE_TEST_DIR ?
@@ -46,8 +16,8 @@ const testRoot = process.env.NODE_TEST_DIR ?
4616
const tmpdirName = '.tmp.' + (process.env.TEST_THREAD_ID || '0');
4717
const tmpPath = path.join(testRoot, tmpdirName);
4818

49-
function refresh(opts = {}) {
50-
rimrafSync(this.path, opts);
19+
function refresh() {
20+
rimrafSync(this.path);
5121
fs.mkdirSync(this.path);
5222
}
5323

test/parallel/parallel.status

-4
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ test-fs-stat-bigint: PASS,FLAKY
1111
test-net-connect-options-port: PASS,FLAKY
1212

1313
[$system==win32]
14-
# https://github.com/nodejs/node/issues/30620
15-
test-child-process-fork-exec-path: PASS,FLAKY
1614
# https://github.com/nodejs/node/issues/20750
1715
test-http2-client-upload: PASS,FLAKY
1816
# https://github.com/nodejs/node/issues/20750
@@ -23,8 +21,6 @@ test-http2-compat-client-upload-reject: PASS,FLAKY
2321
test-http2-multistream-destroy-on-read-tls: PASS,FLAKY
2422
# https://github.com/nodejs/node/issues/20750
2523
test-http2-pipe: PASS,FLAKY
26-
# https://github.com/nodejs/node/issues/30844
27-
test-module-loading-globalpaths: PASS,FLAKY
2824
# https://github.com/nodejs/node/issues/23277
2925
test-worker-memory: PASS,FLAKY
3026
# https://github.com/nodejs/node/issues/30846

0 commit comments

Comments
 (0)