Closed Bug 1522874 Opened 5 years ago Closed 5 years ago

Race condition in cleardata/tests/unit/test_downloads.js

Categories

(Toolkit :: Downloads API, enhancement, P1)

enhancement

Tracking

()

RESOLVED FIXED
mozilla67
Tracking Status
firefox67 --- fixed

People

(Reporter: jorendorff, Assigned: baku)

References

Details

Attachments

(1 file)

Over in bug 1495072, I'm changing await to be faster. This makes a few tests fail, including this one:

https://searchfox.org/mozilla-central/rev/c035ee7d3a5cd6913e7143e1bce549ffb4a566ff/toolkit/components/cleardata/tests/unit/test_downloads.js#72-73

I managed to trigger this by editing the test, with no changes to await: if I add await Promise.resolve(); at line 69, the test fails.

The test assumes that the second download, the one that is started on line 56, is still active by the time we call Services.clearData.deleteData. If the download has already completed, deleteData will remove both downloads from the list.

baku, is there a way to make sure the download is still active when deleteData runs? If not, what can I do with this test?

Flags: needinfo?(amarchesini)

I noticed something else funny: the three methods of DownloadsCleaner all use a .then handler that returns undefined.

These methods always return promises that are already resolved, even though the downloads have not been removed yet.

So, even though ClearDataService._deleteInternal looks like it waits for the download-deleting process to be done, I think it actually isn't waiting for anything; the callback is called after 1 microtask tick regardless.

Anyway, fixing that doesn't fix the race condition in comment 0, so it's sort of beside the point.

Attached patch await.patchSplinter Review
Assignee: nobody → amarchesini
Flags: needinfo?(amarchesini)
Attachment #9039833 - Flags: review?(jhofmann)
Priority: -- → P1
Comment on attachment 9039833 [details] [diff] [review]
await.patch

Review of attachment 9039833 [details] [diff] [review]:
-----------------------------------------------------------------

Sorry for the delay :)
Attachment #9039833 - Flags: review?(jhofmann) → review+
Status: NEW → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla67
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: