I am having a weird issue with testing Coroutines,...
# coroutines
a
I am having a weird issue with testing Coroutines, converted to RxJava2 with
asSingle(CommonPool)
In a unit-test class, I have 2 different tests. Each one of them uses
test()
method from RxJava2 to assert the value Problem is, every time I run my tests, on of them fails, but only one of them. If I comment away one of the tests – the other one always passes. It feels like some threading issue, anybody had similar problems?
Basically, test that is run second always fails in my scenario
Problem was in
CommonPool
that was hardcoded inside the class and not replaced with
Unconfined
in the unit test
g
Maybe you could provide some self contained example of this issue
a
Copy code
class ApiCall() {
  fun execute(): Single<Data> {
    async { ... }.asSingle(CommonPool)
  }
}

class ApiCallTest {
   val classToTest = ApiCall()

  @Test
  fun test1() {
   classToTest.execute().test().assertValue(testValue)
  }

  @Test
  fun test2() {
   classToTest.execute().test().assertValue(testValue)
  }
}
Along these lines. Do you need actual running example?
Would be great if Kotlin Playground could support 3rd party libraries, like RxKotlin