mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 12:20:27 +01:00
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: https://github.com/nodejs/node/issues/30620
Fixes: https://github.com/nodejs/node/issues/30844
PR-URL: https://github.com/nodejs/node/pull/30849
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
parent
973b5c02bb
commit
edf654d43e
|
|
@ -8,8 +8,7 @@ const { checkInvocations } = require('./hook-checks');
|
||||||
const tmpdir = require('../common/tmpdir');
|
const tmpdir = require('../common/tmpdir');
|
||||||
const net = require('net');
|
const net = require('net');
|
||||||
|
|
||||||
// Spawning messes up `async_hooks` state.
|
tmpdir.refresh();
|
||||||
tmpdir.refresh({ spawn: false });
|
|
||||||
|
|
||||||
const hooks = initHooks();
|
const hooks = initHooks();
|
||||||
hooks.enable();
|
hooks.enable();
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ const path = require('path');
|
||||||
if (!common.isMainThread)
|
if (!common.isMainThread)
|
||||||
common.skip('Worker bootstrapping works differently -> different async IDs');
|
common.skip('Worker bootstrapping works differently -> different async IDs');
|
||||||
|
|
||||||
tmpdir.refresh({ spawn: false });
|
tmpdir.refresh();
|
||||||
|
|
||||||
const file1 = path.join(tmpdir.path, 'file1');
|
const file1 = path.join(tmpdir.path, 'file1');
|
||||||
const file2 = path.join(tmpdir.path, 'file2');
|
const file2 = path.join(tmpdir.path, 'file2');
|
||||||
|
|
|
||||||
|
|
@ -898,11 +898,7 @@ The `tmpdir` module supports the use of a temporary directory for testing.
|
||||||
|
|
||||||
The realpath of the testing temporary directory.
|
The realpath of the testing temporary directory.
|
||||||
|
|
||||||
### refresh(\[opts\])
|
### refresh()
|
||||||
|
|
||||||
* `opts` [<Object>][] (optional) Extra options.
|
|
||||||
* `spawn` [<boolean>][] (default: `true`) Indicates that `refresh` is
|
|
||||||
allowed to optionally spawn a subprocess.
|
|
||||||
|
|
||||||
Deletes and recreates the testing temporary directory.
|
Deletes and recreates the testing temporary directory.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,45 +1,12 @@
|
||||||
/* eslint-disable node-core/require-common-first, node-core/required-modules */
|
/* eslint-disable node-core/require-common-first, node-core/required-modules */
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const { execSync } = require('child_process');
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const { debuglog } = require('util');
|
|
||||||
const { isMainThread } = require('worker_threads');
|
const { isMainThread } = require('worker_threads');
|
||||||
|
|
||||||
const debug = debuglog('test/tmpdir');
|
function rimrafSync(pathname) {
|
||||||
|
fs.rmdirSync(pathname, { maxRetries: 3, recursive: true });
|
||||||
function rimrafSync(pathname, { spawn = true } = {}) {
|
|
||||||
const st = (() => {
|
|
||||||
try {
|
|
||||||
return fs.lstatSync(pathname);
|
|
||||||
} catch (e) {
|
|
||||||
if (fs.existsSync(pathname))
|
|
||||||
throw new Error(`Something wonky happened rimrafing ${pathname}`);
|
|
||||||
debug(e);
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
|
|
||||||
// If (!st) then nothing to do.
|
|
||||||
if (!st) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// On Windows first try to delegate rmdir to a shell.
|
|
||||||
if (spawn && process.platform === 'win32' && st.isDirectory()) {
|
|
||||||
try {
|
|
||||||
// Try `rmdir` first.
|
|
||||||
execSync(`rmdir /q /s ${pathname}`, { timeout: 1000 });
|
|
||||||
} catch (e) {
|
|
||||||
// Attempt failed. Log and carry on.
|
|
||||||
debug(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fs.rmdirSync(pathname, { recursive: true, maxRetries: 5 });
|
|
||||||
|
|
||||||
if (fs.existsSync(pathname))
|
|
||||||
throw new Error(`Unable to rimraf ${pathname}`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const testRoot = process.env.NODE_TEST_DIR ?
|
const testRoot = process.env.NODE_TEST_DIR ?
|
||||||
|
|
@ -52,8 +19,8 @@ const tmpdirName = '.tmp.' +
|
||||||
const tmpPath = path.join(testRoot, tmpdirName);
|
const tmpPath = path.join(testRoot, tmpdirName);
|
||||||
|
|
||||||
let firstRefresh = true;
|
let firstRefresh = true;
|
||||||
function refresh(opts = {}) {
|
function refresh() {
|
||||||
rimrafSync(this.path, opts);
|
rimrafSync(this.path);
|
||||||
fs.mkdirSync(this.path);
|
fs.mkdirSync(this.path);
|
||||||
|
|
||||||
if (firstRefresh) {
|
if (firstRefresh) {
|
||||||
|
|
@ -70,7 +37,7 @@ function onexit() {
|
||||||
process.chdir(testRoot);
|
process.chdir(testRoot);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
rimrafSync(tmpPath, { spawn: false });
|
rimrafSync(tmpPath);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Can\'t clean tmpdir:', tmpPath);
|
console.error('Can\'t clean tmpdir:', tmpPath);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,6 @@ test-fs-stat-bigint: PASS,FLAKY
|
||||||
test-net-connect-options-port: PASS,FLAKY
|
test-net-connect-options-port: PASS,FLAKY
|
||||||
|
|
||||||
[$system==win32]
|
[$system==win32]
|
||||||
# https://github.com/nodejs/node/issues/30620
|
|
||||||
test-child-process-fork-exec-path: PASS,FLAKY
|
|
||||||
# https://github.com/nodejs/node/issues/20750
|
# https://github.com/nodejs/node/issues/20750
|
||||||
test-http2-client-upload: PASS,FLAKY
|
test-http2-client-upload: PASS,FLAKY
|
||||||
# https://github.com/nodejs/node/issues/20750
|
# https://github.com/nodejs/node/issues/20750
|
||||||
|
|
@ -23,8 +21,6 @@ test-http2-compat-client-upload-reject: PASS,FLAKY
|
||||||
test-http2-multistream-destroy-on-read-tls: PASS,FLAKY
|
test-http2-multistream-destroy-on-read-tls: PASS,FLAKY
|
||||||
# https://github.com/nodejs/node/issues/20750
|
# https://github.com/nodejs/node/issues/20750
|
||||||
test-http2-pipe: PASS,FLAKY
|
test-http2-pipe: PASS,FLAKY
|
||||||
# https://github.com/nodejs/node/issues/30844
|
|
||||||
test-module-loading-globalpaths: PASS,FLAKY
|
|
||||||
# https://github.com/nodejs/node/issues/23277
|
# https://github.com/nodejs/node/issues/23277
|
||||||
test-worker-memory: PASS,FLAKY
|
test-worker-memory: PASS,FLAKY
|
||||||
# https://github.com/nodejs/node/issues/30846
|
# https://github.com/nodejs/node/issues/30846
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user