Closed Bug 1899772 Opened 1 year ago Closed 1 year ago

Make sure MockExtension/ExtensionWrapper terminateBackground test helpers does not silently fail to terminate the backgrond context right away

Categories

(WebExtensions :: General, task, P2)

task

Tracking

(firefox129 fixed)

RESOLVED FIXED
129 Branch
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.

See Also: → 1901294
Assignee: nobody → lgreco
Status: NEW → ASSIGNED
Priority: P3 → P2
Pushed by luca.greco@alcacoop.it: https://hg.mozilla.org/integration/autoland/rev/9aa1579996da Assert backgroundState in test extension wrapper terminateBackground method. r=robwu
Status: ASSIGNED → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
Target Milestone: --- → 129 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: