I am trying to test a repeatWhen with a delay but ...
# rx
b
I am trying to test a repeatWhen with a delay but am unable to get any results other than the first one
Copy code
@Test fun `test poll`() {
    open class MyClient {
        fun fetchItemFromServer(): Single<Boolean> = Single.just(true)
    }

    val testScheduler = TestScheduler()
    val client = mock<MyClient>()

    whenever(client.fetchItemFromServer())
            .thenReturn(Single.just(false), Single.just(true))

    val test = client.fetchItemFromServer()
            .repeatWhen { it.delay(10, TimeUnit.SECONDS, testScheduler) }
            .distinctUntilChanged()
            .test()

    testScheduler.advanceTimeBy(10, TimeUnit.SECONDS)

    test.assertResult(false, true)
}
d
advanceTimeBy
is working correctly here, the issue is in the mocks. You are getting only a first value because resubscribtion from
repeatWhen
returns
false
again which is filtered by the
distinctUntilChanged
b
Hmm… I thought maybe another advanceTimeBy would work but it’s not. Is there another way to setup mocks or do I just have to get creative?
I figured it out. Had to use a Single.defer with my values I want instead of the when statements returns false, true. Thank you for pointing me in the right direction