Use structured concurrency for sync jobs #157
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The jobs to download and upload data (as well as the one forwarding sync status changes) are all operating independently from each other, which can potentially cause issues stopping these jobs as once.
This adopts a
SupervisorJob
for the three, allowing us to cancel just one job indisconnect
that's guaranteed to get them all.I've also slightly refactored our test client so that it properly forwards cancellations (when we cancel the sync jobs, that propagates to
SyncStream.streamingSyncRequest
in therequest.execute
block). With the mock HTTP engine from ktor we unfortunately have no access to that scope, but by implementing a fairly trivial custom engine we can implement the same functionality while also reporting downstream listeners being cancelled.This then allows testing that calling
disconnect()
orclose()
on a database does indeed close the underlying HTTP response stream.