Skip to content

Commit

Permalink
Change Observer: Fix flaky test caused by cleanup code
Browse files Browse the repository at this point in the history
The cleanup code for `directory_test`s may fail when it attempts to
remove a a entry that no longer exists. This changes it to ignore when
it fails to remove an entry since it doesn't matter as long as it
doesn't exist anymore.

This may be due to a race issue where cleanup code from a previous test
hadn't finished deleting all its entries when `directory_test` takes a
snapshot of them. But it does before `directory_test` can remove the
entry.

Fixed: 377480361
Change-Id: I5c173ba6afae5ddf7db0a4d8d154319dd5f0fb85
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6001305
Reviewed-by: Daseul Lee <[email protected]>
Commit-Queue: Nathan Memmott <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1380545}
  • Loading branch information
Nathan Memmott authored and chromium-wpt-export-bot committed Nov 8, 2024
1 parent a0e2da6 commit 1cf0f9e
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions fs/resources/sandboxed-fs-test-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,22 @@ async function cleanupDirectory(dir, ignoreRejections) {
entry =>
dir.removeEntry(entry.name, {recursive: entry.kind === 'directory'}));

// Wait for them all to resolve or reject.
if (ignoreRejections) {
await Promise.allSettled(remove_entry_promises);
} else {
await Promise.all(remove_entry_promises);
}
// Wait for them all to resolve or reject, ignoring any rejections.
await Promise.allSettled(remove_entry_promises);
}

function directory_test(func, description) {
promise_test(async t => {
const dir = await navigator.storage.getDirectory();

// To be extra resilient against bad tests, cleanup before every test.
await cleanupDirectory(dir, /*ignoreRejections=*/ false);
await cleanupDirectory(dir);

// Cleanup after every test.
t.add_cleanup(async () => {
// Ignore any rejections since other cleanup code may have deleted them
// before we could.
await cleanupDirectory(dir, /*ignoreRejections=*/ true);
await cleanupDirectory(dir);
});


Expand Down

0 comments on commit 1cf0f9e

Please sign in to comment.