alex.tavella
03/31/2021, 9:10 PMThis job has not completed yet
on the following test:
@Test
fun requestWithTimeout_serverRespondsInTime_returnsResponse() = coroutinesRule.testDispatcher.runBlockingTest {
val body = "{ field: Test }"
val response = MockResponse()
.setResponseCode(HttpURLConnection.HTTP_OK)
.setBody(body)
.throttleBody(body.length.toLong() / 2, 9, TimeUnit.SECONDS)
mockWebServer.enqueue(response)
val actual = service.requestWithTimeout(20_000)
assertEquals(ResponseTest("Test"), actual)
}
jw
03/31/2021, 9:10 PMursus
03/31/2021, 9:11 PMalex.tavella
03/31/2021, 9:12 PMrunBlocking
and the test passes but it takes too long to completejw
03/31/2021, 9:32 PMursus
03/31/2021, 9:54 PMjw
03/31/2021, 9:56 PMursus
03/31/2021, 10:00 PMjw
03/31/2021, 10:44 PMursus
03/31/2021, 11:41 PMjw
04/01/2021, 12:24 AMursus
04/01/2021, 12:25 AMjw
04/01/2021, 12:35 AMursus
04/01/2021, 12:49 AMPresenter(someRepository: Repository) {
val state: Flow<State> get() = _state
private val _state = MutableStateFlow()
init {
scope.launch {
someRepository.whatever
.someTransforms
.collect {
_state.value = it
}
}
}
fun someClick() {
scope.launch {
_state.value = Loading
someRepository.doSomething()
_state.value = NotLoading
}
}
}
or are they jsut transformations, and not keep state?jw
04/01/2021, 12:51 AMursus
04/01/2021, 12:53 AMprivate val scope = CoroutineScope(SupervisorJob() + Dispatchers.main)
or rather the disaptcher instance is injected via ctor
and the question is what should one replace it with during tests. I was used to rx and its Schedulers.trampoline() and keeping everything blocking; but MutableStateFlow doesnt seem to work the same when used with Dispatchers.Unconfined