mercredi 3 mai 2017

Rx-Kotlin awaitTerminalEvent never getting onComplete

I am trying to get a better understanding of how to do unit tests with Rx-Kotlin, but I have not been able to successfully set the subject to "completed". As a result, I am always waiting for the timeout of 5 seconds (the onComplete should be immediate) and then fail on assertComplete.

My understanding of awaitTerminalEvent is that it should only block until the onComplete is called. I have also looked into TestScheduler, but I do not believe that it should be required here.

Any help or documentation that can lead me in the right direction would be much appreciated.

@Test
fun testObservable() {
    val subject = BehaviorSubject.create<Int>()
    subject.onNext(0)

    TestSubscriber<Int>().apply {
        subject.subscribe({
            System.out.println(it)
            subject.onNext(1)
            subject.onComplete()
        })

        this.awaitTerminalEvent(5, TimeUnit.SECONDS)
        this.assertComplete()
        this.assertValue(1)
    }
}

Aucun commentaire:

Enregistrer un commentaire