Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib,test: increase retryDelay to remove directories on Windows #1048

Merged
merged 1 commit into from Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 3 additions & 6 deletions lib/temp-directory.js
Expand Up @@ -3,6 +3,8 @@ import { promises as fs } from 'fs';
import { randomUUID } from 'crypto';
import { tmpdir } from 'os';

import { removeDirectory } from './utils.js';

export async function create(context) {
if (context.options && context.options.tmpDir) {
context.path = join(context.options.tmpDir, randomUUID());
Expand Down Expand Up @@ -33,12 +35,7 @@ export let remove = async function remove(context) {
`${context.module.name} rm.tempdir`,
context.path
);
await fs.rm(context.path, {
recursive: true,
force: true,
maxRetries: 10,
retryDelay: 10
});
await removeDirectory(context.path);
};

// Used in tests to simulate errors in rimraf.
Expand Down
14 changes: 14 additions & 0 deletions lib/utils.js
@@ -0,0 +1,14 @@
import fs from 'node:fs/promises';

/**
* Remove directory recursively with retries for Windows.
* @param path
*/
export async function removeDirectory(path) {
await fs.rm(path, {
recursive: true,
force: true,
maxRetries: 10,
retryDelay: 50
});
}
8 changes: 2 additions & 6 deletions test/npm/test-npm-install.js
Expand Up @@ -7,6 +7,7 @@ import tap from 'tap';

import { getPackageManagers } from '../../lib/package-manager/index.js';
import packageManagerInstall from '../../lib/package-manager/install.js';
import { removeDirectory } from '../../lib/utils.js';
import { npmContext } from '../helpers/make-context.js';

const { test } = tap;
Expand Down Expand Up @@ -103,10 +104,5 @@ test('npm-install: failed install', async (t) => {
});

tap.teardown(async () => {
await fs.rm(sandbox, {
recursive: true,
force: true,
maxRetries: 10,
retryDelay: 10
});
await removeDirectory(sandbox);
});
10 changes: 3 additions & 7 deletions test/npm/test-npm-test.js
Expand Up @@ -5,9 +5,10 @@ import { existsSync, promises as fs } from 'fs';

import tap from 'tap';

import { npmContext } from '../helpers/make-context.js';
import { getPackageManagers } from '../../lib/package-manager/index.js';
import { test as packageManagerTest } from '../../lib/package-manager/test.js';
import { removeDirectory } from '../../lib/utils.js';
import { npmContext } from '../helpers/make-context.js';

const { test } = tap;
const __dirname = dirname(fileURLToPath(import.meta.url));
Expand Down Expand Up @@ -185,10 +186,5 @@ test('npm-test: tmpdir is redirected', async (t) => {
});

tap.teardown(async () => {
await fs.rm(sandbox, {
recursive: true,
force: true,
maxRetries: 10,
retryDelay: 10
});
await removeDirectory(sandbox);
});
8 changes: 2 additions & 6 deletions test/pnpm/test-pnpm-install.js
Expand Up @@ -7,6 +7,7 @@ import tap from 'tap';

import { getPackageManagers } from '../../lib/package-manager/index.js';
import packageManagerInstall from '../../lib/package-manager/install.js';
import { removeDirectory } from '../../lib/utils.js';
import { npmContext } from '../helpers/make-context.js';

const { test } = tap;
Expand Down Expand Up @@ -79,10 +80,5 @@ test('pnpm-install: failed install', async (t) => {
});

tap.teardown(async () => {
await fs.rm(sandbox, {
recursive: true,
force: true,
maxRetries: 10,
retryDelay: 10
});
await removeDirectory(sandbox);
});
10 changes: 3 additions & 7 deletions test/pnpm/test-pnpm-test.js
Expand Up @@ -5,9 +5,10 @@ import { fileURLToPath } from 'url';

import tap, { test } from 'tap';

import { npmContext } from '../helpers/make-context.js';
import { getPackageManagers } from '../../lib/package-manager/index.js';
import { test as packageManagerTest } from '../../lib/package-manager/test.js';
import { removeDirectory } from '../../lib/utils.js';
import { npmContext } from '../helpers/make-context.js';

const __dirname = dirname(fileURLToPath(import.meta.url));

Expand Down Expand Up @@ -181,10 +182,5 @@ test('pnpm-test: tmpdir is redirected', async (t) => {
});

tap.teardown(async () => {
await fs.rm(sandbox, {
recursive: true,
force: true,
maxRetries: 10,
retryDelay: 10
});
await removeDirectory(sandbox);
});
8 changes: 2 additions & 6 deletions test/reporter/test-reporter-junit.js
Expand Up @@ -9,6 +9,7 @@ import _ from 'lodash';
import xml2js from 'xml2js';

import junitReporter from '../../lib/reporter/junit.js';
import { removeDirectory } from '../../lib/utils.js';

const { test } = tap;
const parseString = promisify(xml2js.parseString);
Expand Down Expand Up @@ -154,10 +155,5 @@ test('reporter.junit(): append to disk', (t) => {
});

tap.teardown(async () => {
await fs.rm(sandbox, {
recursive: true,
force: true,
maxRetries: 10,
retryDelay: 10
});
await removeDirectory(sandbox);
});
8 changes: 2 additions & 6 deletions test/reporter/test-reporter-tap.js
Expand Up @@ -10,6 +10,7 @@ import { Parser } from 'tap-parser';
import str from 'string-to-stream';

import tapReporter from '../../lib/reporter/tap.js';
import { removeDirectory } from '../../lib/utils.js';

const fixtures = JSON.parse(
readFileSync(new URL('../fixtures/reporter-fixtures.json', import.meta.url))
Expand Down Expand Up @@ -132,10 +133,5 @@ test('reporter.tap(): append to disk when file does not exist', (t) => {
});

tap.teardown(async () => {
await fs.rm(sandbox, {
recursive: true,
force: true,
maxRetries: 10,
retryDelay: 10
});
await removeDirectory(sandbox);
});
8 changes: 2 additions & 6 deletions test/test-grab-project.js
Expand Up @@ -10,6 +10,7 @@ import { promises as fs } from 'fs';
import tap from 'tap';

import { grabProject } from '../lib/grab-project.js';
import { removeDirectory } from '../lib/utils.js';

const { test } = tap;

Expand Down Expand Up @@ -170,10 +171,5 @@ test('grab-project: timeout', async (t) => {
});

tap.teardown(async () => {
await fs.rm(sandbox, {
recursive: true,
force: true,
maxRetries: 10,
retryDelay: 10
});
await removeDirectory(sandbox);
});
8 changes: 2 additions & 6 deletions test/yarn/test-yarn-install.js
Expand Up @@ -7,6 +7,7 @@ import tap from 'tap';

import { getPackageManagers } from '../../lib/package-manager/index.js';
import packageManagerInstall from '../../lib/package-manager/install.js';
import { removeDirectory } from '../../lib/utils.js';
import { npmContext } from '../helpers/make-context.js';

const { test } = tap;
Expand Down Expand Up @@ -81,10 +82,5 @@ test('yarn-install: failed install', async (t) => {
});

tap.teardown(async () => {
await fs.rm(sandbox, {
recursive: true,
force: true,
maxRetries: 10,
retryDelay: 10
});
await removeDirectory(sandbox);
});
8 changes: 2 additions & 6 deletions test/yarn/test-yarn-test.js
Expand Up @@ -8,6 +8,7 @@ import tap, { test } from 'tap';
import { npmContext } from '../helpers/make-context.js';
import { getPackageManagers } from '../../lib/package-manager/index.js';
import { test as packageManagerTest } from '../../lib/package-manager/test.js';
import { removeDirectory } from '../../lib/utils.js';

const __dirname = dirname(fileURLToPath(import.meta.url));

Expand Down Expand Up @@ -181,10 +182,5 @@ test('yarn-test: tmpdir is redirected', async (t) => {
});

tap.teardown(async () => {
await fs.rm(sandbox, {
recursive: true,
force: true,
maxRetries: 10,
retryDelay: 10
});
await removeDirectory(sandbox);
});