Make sure MockExtension/ExtensionWrapper terminateBackground test helpers does not silently fail to terminate the backgrond context right away
Categories
(WebExtensions :: General, task, P2)
Tracking
(firefox129 fixed)
| Tracking | Status | |
|---|---|---|
| firefox129 | --- | fixed |
People
(Reporter: rpl, Assigned: rpl)
References
Details
(Whiteboard: [addons-jira])
Attachments
(1 file)
In tests covering the event pages behaviors we often use the terminateBackground method exposed by the extension test wrapper returning by ExtensionTestUtils.loadExtension to force terminate the background context as part of testing the event pages expected behaviors (e.g. respawning on primed event listeners after being suspended).
The current implementation of the terminateBackground test helper may silently fail to terminate the background context by the time its returned promise is resolved, which in most cases may just make the test to take longer (because the background context is not terminated and will be terminated the next time the idle timer will be firing) and so it is also easy to miss.
Follows a quote related to some ideas for improvements around that mentioned by Rob in https://phabricator.services.mozilla.com/D211461#7260649:
we could improve that by changing test-only terminateBackground as follows:
- Await terminateBackground as usual.
- When extension.backgroundState is not "stopped", print a warning that terminateBackground did not terminate the background. This is for
debugging purposes.- Unless the caller opted out, regularly check whether !extension.backgroundContext.pendingRunListenerPromisesCount drops to zero, and if so,
try terminateBackground again.An alternative to the last step is to throw an error if the background has not shut down, unless the caller has opted out. Then we would get hard errors instead of intermittently longer test runs and hard-to-debug timeouts.
Updated•1 year ago
|
| Assignee | ||
Updated•1 year ago
|
| Assignee | ||
Comment 1•1 year ago
|
||
Description
•