Skip to content

Commit

Permalink
test: fix flaky test-fs-promises-file-handle-close
Browse files Browse the repository at this point in the history
Sometimes, the expected warnings were not emitted.
To harden the test:

- Instead of relying on a timeout that raced against the file being
  opened, wait until the file is opened and then schedule GC
  after that.
- Explicitly keep the event loop alive for one turn to make sure
  the warning is being seen.

PR-URL: #31687
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
addaleax committed Feb 10, 2020
1 parent d0413ae commit 5100e84
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions test/parallel/test-fs-promises-file-handle-close.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ async function doOpen() {
return fh;
}

// Perform the file open assignment within a block.
// When the block scope exits, the file handle will
// be eligible for garbage collection.
{
doOpen().then(common.mustCall((fd) => {
assert.strictEqual(typeof fd, 'object');
}));
}

setTimeout(() => global.gc(), 10);
doOpen().then(common.mustCall((fd) => {
assert.strictEqual(typeof fd, 'object');
})).then(common.mustCall(() => {
setImmediate(() => {
// The FileHandle should be out-of-scope and no longer accessed now.
global.gc();

// Wait an extra event loop turn, as the warning is emitted from the
// native layer in an unref()'ed setImmediate() callback.
setImmediate(common.mustCall());
});
}));

0 comments on commit 5100e84

Please sign in to comment.