Skip to content

Commit

Permalink
Add test asserting Rx subscription is disposed after `RibCoroutineWor…
Browse files Browse the repository at this point in the history
…ker.asWorker()` is unbound.
  • Loading branch information
psteiger committed Jul 8, 2024
1 parent 5aafed4 commit df056a0
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,26 @@ class RibCoroutineWorkerTest {
assertThat(gotEmission).isTrue()
}

@Test
fun asWorker_autoDisposeWithCoroutineScope_unbindingWorkerDisposesSubscription() = runTest {
val router = mock<Router<*>>()
val interactor = object : Interactor<Any, Router<*>>() {}
val subject = PublishSubject.create<Unit>()
var disposed = false
val ribCoroutineWorker = RibCoroutineWorker {
subject.doOnDispose { disposed = true }.autoDispose(this).subscribe()
}
val worker = ribCoroutineWorker.asWorker()
InteractorHelper.attach(interactor, Any(), router, null)
val unbinder = WorkerBinder.bind(interactor, worker)
runCurrent()
subject.onNext(Unit)
assertThat(disposed).isFalse()
unbinder.unbind()
runCurrent()
assertThat(disposed).isTrue()
}

@Test
fun testHelperFunction() = runTest {
// Sanity - assert initial state.
Expand Down

0 comments on commit df056a0

Please sign in to comment.