1

I am trying to skip Single.delay() and my test falls with error:

java.lang.AssertionError: Not completed (latch = 1, values = 0, errors = 0, completions = 0)

val testScheduler = TestScheduler()
RxJavaPlugins.setComputationSchedulerHandler { testScheduler }

Single.just("")
        .delay(1, TimeUnit.SECONDS, testScheduler)
        .test()
        .assertComplete()

testScheduler.advanceTimeBy(1, TimeUnit.SECONDS)

this code works ok with Observable, is there any way to skip .delay() for Single?

aldok
  • 17,295
  • 5
  • 53
  • 64

1 Answers1

1

You are asserting immediately before you even moved the time. Assert separately:

val testScheduler = TestScheduler()

val to = Single.just("")
        .delay(1, TimeUnit.SECONDS, testScheduler)
        .test()

to.assertEmpty();

testScheduler.advanceTimeBy(1, TimeUnit.SECONDS)

to.assertComplete();    

Also setting the default scheduler and using a custom scheduler with the operator makes no sense.

akarnokd
  • 69,132
  • 14
  • 157
  • 192