Skip to content

Commit 1b534d5

Browse files
bnoordhuisMylesBorins
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: #30620Fixes: #30844 PR-URL: #30849 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent 8bf0da6 commit 1b534d5

5 files changed

Lines changed: 8 additions & 50 deletions

File tree

‎test/async-hooks/test-pipeconnectwrap.js‎

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

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

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

‎test/async-hooks/test-statwatcher.js‎

Lines changed: 1 addition & 1 deletion
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
constfile1=path.join(tmpdir.path,'file1');
1717
constfile2=path.join(tmpdir.path,'file2');

‎test/common/README.md‎

Lines changed: 1 addition & 5 deletions
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‎

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,12 @@
11
/* eslint-disable node-core/require-common-first, node-core/required-modules */
22
'use strict';
33

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

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

4512
consttestRoot=process.env.NODE_TEST_DIR ?
@@ -52,8 +19,8 @@ const tmpdirName = '.tmp.' +
5219
consttmpPath=path.join(testRoot,tmpdirName);
5320

5421
letfirstRefresh=true;
55-
functionrefresh(opts={}){
56-
rimrafSync(this.path,opts);
22+
functionrefresh(){
23+
rimrafSync(this.path);
5724
fs.mkdirSync(this.path);
5825

5926
if(firstRefresh){
@@ -70,7 +37,7 @@ function onexit() {
7037
process.chdir(testRoot);
7138

7239
try{
73-
rimrafSync(tmpPath,{spawn: false});
40+
rimrafSync(tmpPath);
7441
}catch(e){
7542
console.error('Can\'t clean tmpdir:',tmpPath);
7643

‎test/parallel/parallel.status‎

Lines changed: 0 additions & 4 deletions
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)