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

test: make sure current run result is pushed and reset #54332

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 32 additions & 11 deletions test/parallel/test-runner-run-watch.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import { join } from 'node:path';
if (common.isIBMi)
common.skip('IBMi does not support `fs.watch()`');

if (common.isAIX)
Copy link
Contributor Author

@jakecastelli jakecastelli Aug 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a rough time with CI on AIX previously, I don't know if we should skip it entirely or just skip the test that has 100% failure rate due to the platform limitation (in this case the file deletion test)

common.skip('folder watch capability is limited in AIX.');

// This test updates these files repeatedly,
// Reading them from disk is unreliable due to race conditions.
const fixtureContent = {
Expand Down Expand Up @@ -60,6 +63,8 @@ async function testWatch({ fileToUpdate, file, action = 'update', cwd = tmpdir.p

const testUpdate = async () => {
await ran1.promise;
runs.push(currentRun);
currentRun = '';
const content = fixtureContent[fileToUpdate];
const path = fixturePaths[fileToUpdate];
const interval = setInterval(() => writeFileSync(path, content), common.platformTimeout(1000));
Expand All @@ -68,6 +73,9 @@ async function testWatch({ fileToUpdate, file, action = 'update', cwd = tmpdir.p
clearInterval(interval);
child.kill();
await once(child, 'exit');

assert.strictEqual(runs.length, 2);

for (const run of runs) {
assert.doesNotMatch(run, /run\(\) is being called recursively/);
assert.match(run, /# tests 1/);
Expand All @@ -79,6 +87,8 @@ async function testWatch({ fileToUpdate, file, action = 'update', cwd = tmpdir.p

const testRename = async () => {
await ran1.promise;
runs.push(currentRun);
currentRun = '';
const fileToRenamePath = tmpdir.resolve(fileToUpdate);
const newFileNamePath = tmpdir.resolve(`test-renamed-${fileToUpdate}`);
const interval = setInterval(() => renameSync(fileToRenamePath, newFileNamePath), common.platformTimeout(1000));
Expand All @@ -88,22 +98,31 @@ async function testWatch({ fileToUpdate, file, action = 'update', cwd = tmpdir.p
child.kill();
await once(child, 'exit');

for (const run of runs) {
assert.doesNotMatch(run, /run\(\) is being called recursively/);
if (action === 'rename2') {
assert.match(run, /MODULE_NOT_FOUND/);
} else {
assert.doesNotMatch(run, /MODULE_NOT_FOUND/);
}
assert.match(run, /# tests 1/);
assert.match(run, /# pass 1/);
assert.match(run, /# fail 0/);
assert.match(run, /# cancelled 0/);
assert.strictEqual(runs.length, 2);

const [firstRun, secondRun] = runs;
assert.match(firstRun, /# tests 1/);
assert.match(firstRun, /# pass 1/);
assert.match(firstRun, /# fail 0/);
assert.match(firstRun, /# cancelled 0/);
assert.doesNotMatch(firstRun, /run\(\) is being called recursively/);

if (action === 'rename2') {
assert.match(secondRun, /MODULE_NOT_FOUND/);
return;
}

assert.match(secondRun, /# tests 1/);
assert.match(secondRun, /# pass 1/);
assert.match(secondRun, /# fail 0/);
assert.match(secondRun, /# cancelled 0/);
assert.doesNotMatch(secondRun, /run\(\) is being called recursively/);
};

const testDelete = async () => {
await ran1.promise;
runs.push(currentRun);
currentRun = '';
const fileToDeletePath = tmpdir.resolve(fileToUpdate);
const interval = setInterval(() => {
if (existsSync(fileToDeletePath)) {
Expand All @@ -118,6 +137,8 @@ async function testWatch({ fileToUpdate, file, action = 'update', cwd = tmpdir.p
child.kill();
await once(child, 'exit');

assert.strictEqual(runs.length, 2);

for (const run of runs) {
assert.doesNotMatch(run, /MODULE_NOT_FOUND/);
}
Expand Down
15 changes: 15 additions & 0 deletions test/parallel/test-runner-watch-mode.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import tmpdir from '../common/tmpdir.js';
if (common.isIBMi)
common.skip('IBMi does not support `fs.watch()`');

if (common.isAIX)
common.skip('folder watch capability is limited in AIX.');

let fixturePaths;

// This test updates these files repeatedly,
Expand Down Expand Up @@ -54,6 +57,8 @@ async function testWatch({ fileToUpdate, file, action = 'update' }) {

const testUpdate = async () => {
await ran1.promise;
runs.push(currentRun);
currentRun = '';
const content = fixtureContent[fileToUpdate];
const path = fixturePaths[fileToUpdate];
const interval = setInterval(() => writeFileSync(path, content), common.platformTimeout(1000));
Expand All @@ -63,6 +68,8 @@ async function testWatch({ fileToUpdate, file, action = 'update' }) {
child.kill();
await once(child, 'exit');

assert.strictEqual(runs.length, 2);

for (const run of runs) {
assert.match(run, /# tests 1/);
assert.match(run, /# pass 1/);
Expand All @@ -73,6 +80,8 @@ async function testWatch({ fileToUpdate, file, action = 'update' }) {

const testRename = async () => {
await ran1.promise;
runs.push(currentRun);
currentRun = '';
const fileToRenamePath = tmpdir.resolve(fileToUpdate);
const newFileNamePath = tmpdir.resolve(`test-renamed-${fileToUpdate}`);
const interval = setInterval(() => renameSync(fileToRenamePath, newFileNamePath), common.platformTimeout(1000));
Expand All @@ -82,6 +91,8 @@ async function testWatch({ fileToUpdate, file, action = 'update' }) {
child.kill();
await once(child, 'exit');

assert.strictEqual(runs.length, 2);

for (const run of runs) {
assert.match(run, /# tests 1/);
assert.match(run, /# pass 1/);
Expand All @@ -92,6 +103,8 @@ async function testWatch({ fileToUpdate, file, action = 'update' }) {

const testDelete = async () => {
await ran1.promise;
runs.push(currentRun);
currentRun = '';
const fileToDeletePath = tmpdir.resolve(fileToUpdate);
const interval = setInterval(() => {
if (existsSync(fileToDeletePath)) {
Expand All @@ -106,6 +119,8 @@ async function testWatch({ fileToUpdate, file, action = 'update' }) {
child.kill();
await once(child, 'exit');

assert.strictEqual(runs.length, 2);

for (const run of runs) {
assert.doesNotMatch(run, /MODULE_NOT_FOUND/);
}
Expand Down
Loading