Repository navigation
feat(clustering): allow injecting coroutine contexts into ClusterManager - #1822
Conversation
Code Coverage
Files
|
|
Thanks for this PR, @kikoso! Injecting dispatchers into Here are a few recommendations before landing: 1. Standardize on
|
Rename mMap to map, add convenience constructors without MarkerManager, use a SupervisorJob for the cluster scope and clear the renderer mock in the injected contexts test.
Done.
Added both. The types don't clash with the existing
Good point, changed to
Agreed, it was confusing to read. The test now clears the mock after the initial run and checks All in 0a89a83. Thanks for the review, Dale! |
ClusterManagerhardcodesDispatchers.Mainfor delivering clusters to the renderer andDispatchers.Defaultfor computing them. Tests can swap Main withDispatchers.setMain(), but there is no way to replace Default, socluster()always hops to a real background thread and tests that depend on it are flaky.This adds a constructor that takes a
mainContextand abackgroundContext:The existing constructors are unchanged and keep using
Dispatchers.Main/Dispatchers.Default. The new parameters live on a separate constructor rather than as extra default arguments, because adding defaulted parameters would change the synthetic$defaultconstructor that already-compiled Kotlin callers link against.apiDumpshows only one added constructor.Note that this covers the clustering computation in
ClusterManager.cluster().DefaultClusterRendererstill uses its own executor and main-looper handler for marker rendering.Testing
ClusterManagerTest.testClusterRunsOnInjectedContextsuses aStandardTestDispatcherfor both contexts and checks clusters reach the renderer only after the scheduler advances../gradlew :clustering:testDebugUnitTest :clustering:apiCheck spotlessCheck :clustering:lintpasses.