Skip to content

Commit

Permalink
test: fix flaky test-runner-cli-concurrency.js
Browse files Browse the repository at this point in the history
This test was flaky on Windows when trying to clean up the
tmp directory between tests. This commit updates the test to
not delete anything between tests.

Fixes: nodejs#50101
  • Loading branch information
cjihrig committed Oct 10, 2023
1 parent ac2a68c commit e4a1b3d
Showing 1 changed file with 28 additions and 15 deletions.
43 changes: 28 additions & 15 deletions test/parallel/test-runner-cli-concurrency.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,56 @@ const common = require('../common');
const tmpdir = require('../common/tmpdir');
const { deepStrictEqual, strictEqual } = require('node:assert');
const { spawnSync } = require('node:child_process');
const { readdirSync, writeFileSync } = require('node:fs');
const { mkdirSync, readdirSync, writeFileSync } = require('node:fs');
const { join } = require('node:path');
const { beforeEach, test } = require('node:test');
const { test } = require('node:test');

function createTestFile(name) {
writeFileSync(join(tmpdir.path, name), `
const path = join(tmpdir.path, name);
writeFileSync(path, `
const fs = require('node:fs');
const { join } = require('node:path');
fs.unlinkSync(__filename);
fs.writeFileSync(join(process.cwd(), '${name}.out'), 'x');
setTimeout(() => {}, 1_000_000_000);
`);
return path;
}

beforeEach(() => {
tmpdir.refresh();
createTestFile('test-1.js');
createTestFile('test-2.js');
});
let cnt = 0;
function nextDir() {
const path = join(tmpdir.path, String(cnt));
cnt++;
mkdirSync(path);
return path;
}

tmpdir.refresh();
const test1 = createTestFile('test-1.js');
const test2 = createTestFile('test-2.js');

test('concurrency of one', () => {
const cp = spawnSync(process.execPath, ['--test', '--test-concurrency=1'], {
cwd: tmpdir.path,
const cwd = nextDir();
const args = ['--test', '--test-concurrency=1', test1, test2];
const cp = spawnSync(process.execPath, args, {
cwd,
timeout: common.platformTimeout(1000),
});

strictEqual(cp.stderr.toString(), '');
strictEqual(cp.error.code, 'ETIMEDOUT');
deepStrictEqual(readdirSync(tmpdir.path), ['test-2.js']);
deepStrictEqual(readdirSync(cwd), ['test-1.js.out']);
});

test('concurrency of two', () => {
const cp = spawnSync(process.execPath, ['--test', '--test-concurrency=2'], {
cwd: tmpdir.path,
const cwd = nextDir();
const args = ['--test', '--test-concurrency=2', test1, test2];
const cp = spawnSync(process.execPath, args, {
cwd,
timeout: common.platformTimeout(1000),
});

strictEqual(cp.stderr.toString(), '');
strictEqual(cp.error.code, 'ETIMEDOUT');
deepStrictEqual(readdirSync(tmpdir.path), []);
deepStrictEqual(readdirSync(cwd), ['test-1.js.out', 'test-2.js.out']);
});

0 comments on commit e4a1b3d

Please sign in to comment.