Skip to content

Commit

Permalink
fixed reroute during destroy
Browse files Browse the repository at this point in the history
  • Loading branch information
VysotskiVadim committed Nov 28, 2023
1 parent 711ad4e commit 5818412
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1289,8 +1289,7 @@ class MapboxNavigation @VisibleForTesting internal constructor(
runInTelemetryContext { telemetry ->
telemetry.destroy(this@MapboxNavigation)
}
threadController.cancelAllNonUICoroutines()
threadController.cancelAllUICoroutines()
threadController.destroy()
ifNonNull(reachabilityObserverId) {
ReachabilityService.removeReachabilityObserver(it)
reachabilityObserverId = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ class ThreadController {
}

fun destroy() {

val reason = CancellationException("thread controller is destroyed")
mainRootJob.cancel(reason)
ioRootJob.cancel(reason)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import kotlinx.coroutines.runBlocking
import org.hamcrest.CoreMatchers.`is`
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNull
import org.junit.Assert.assertThat
import org.junit.Assert.assertTrue
import org.junit.Assert.fail
Expand All @@ -26,7 +27,7 @@ import kotlin.coroutines.suspendCoroutine
class ThreadControllerTest {

@get:Rule
private val testCoroutineRule = MainCoroutineRule()
val testCoroutineRule = MainCoroutineRule()

private val threadController = ThreadController()

Expand Down Expand Up @@ -143,15 +144,25 @@ class ThreadControllerTest {
@Test
fun destroy_thread_controller() {
val handler = CompletableDeferred<Unit>()
var errorMessage: String? = null
threadController.getIOScopeAndRootJob().scope.launch {
handler.await()
fail("IO scope should be cancelled")
errorMessage = "IO scope should be cancelled"
}
threadController.getMainScopeAndRootJob().scope.launch {
handler.await()
fail("UI scope should be cancelled")
errorMessage = "UI scope should be cancelled"
}
threadController.destroy()
handler.complete(Unit)
assertNull(errorMessage)

threadController.getIOScopeAndRootJob().scope.launch {
errorMessage = "IO scope should be cancelled"
}
threadController.getMainScopeAndRootJob().scope.launch {
errorMessage = "UI scope should be cancelled"
}
assertNull(errorMessage)
}
}

0 comments on commit 5818412

Please sign in to comment.