Closed Bug 1980348 Opened 10 months ago Closed 6 months ago

Remove thread marshalling from stores

Categories

(Firefox for Android :: Tooling, task)

All
Android
task

Tracking

()

RESOLVED FIXED
147 Branch
Tracking Status
firefox147 --- fixed

People

(Reporter: polly, Assigned: polly)

References

Details

(Whiteboard: [fxdroid][group6])

Attachments

(3 files, 3 obsolete files)

Our current implementation of Store spins up a new thread each time state is accessed. This makes the call site's code needlessly complex and error-prone as we often have to pull together composite state from multiple asynchronous requests.

If we remove the thread creation and handling from the Store, this would allow users of a Store to make their own decisions about which thread to use. Typically, we expect main thread to be used as the Store contains accessors for in-memory objects - we don't expect these to be long-running operations.

Blocks: 1980350
Blocks: 1980352

The Bugbug bot thinks this bug should belong to the 'Firefox for Android::Tooling' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Component: General → Tooling

This required a few changes:

  1. the Store production code in lib-state no longer spawns a new thread when you dispatch a store action.
  2. Because of this, a lot of tests need to have .join() or .joinBlocking() removed from where they dispatch actions.
  3. Most tests pass after this. But a few fail because either:
  • exceptions were being thrown on background store threads
  • they relied on store actions not having completed before assertions
Assignee: nobody → polly
Attachment #9511408 - Attachment description: WIP: Bug 1980348 - remove thread marshalling from Stores. → Bug 1980348 - remove thread marshalling from Stores.
Status: NEW → ASSIGNED

@Ignore-d this in the previous patch, so i'm fixing that separately.
This test manipulates Tab objects, which are being transitioned between active and inactive states by a time-dependent Flow.
We're testing the storage of these objects, so i've pulled out the logic to compare tabs to its own assertTabSame() function, which looks at the contents of the tabs rather than whether they're currently active.

Also don't think we need to use spy() here for the class under test, so i've dropped in the real thing.

Attachment #9512310 - Attachment description: WIP: Bug 1980348 - fix test that was giving non-deterministic results. → Bug 1980348 - fix test that was giving non-deterministic results.

We don't need this any more with single threaded stores, so we can clean up the tests quite a bit.

Attachment #9512310 - Attachment is obsolete: true
Blocks: 1989622
Attachment #9511408 - Attachment is obsolete: true
Attachment #9512567 - Attachment is obsolete: true

Second attempt with a smaller patch size. (see patch https://phabricator.services.mozilla.com/D263733 for first attempt)
For now Store.dispatch() returns a dummy Job.
This means the api, which is used in a lot of tests, doesn't need to be changed as part of this patch.
This is temporary and will be cleaned up as soon as we are happy with this change - intention is to have the dispatch function not return and clean up all the join()/joinBlocking() thread wrangling in unit tests.

Changes that have been made:

  • remove threading code from Store
  • fix tests than rely on multithreading or throw exceptions on background threads
Attachment #9519739 - Attachment description: WIP: Bug 1980348 - remove thread marshalling from Stores. → Bug 1980348 - remove thread marshalling from Stores.

This means we have to delete join() and joinBlocking() everywhere they are appended to Store.dispatch() (mostly in the unit tests)

This was previously just a passthrough method so we can remove it now. This simplifies a lot of tests.

Regressions: 1999784
Regressions: 2000584
Status: ASSIGNED → RESOLVED
Closed: 6 months ago
Resolution: --- → FIXED
Target Milestone: --- → 147 Branch
Regressions: 2000191
Regressions: 2002831
See Also: → 2002831
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: