Skip to content
This repository was archived by the owner on Sep 5, 2023. It is now read-only.

Commit b63f82c

Browse files
author
Fran Montiel
committed
Workaround for crash when using runBlockingTest
- Kotlin/kotlinx.coroutines#1222
1 parent 167cf39 commit b63f82c

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

harmony-kotlin/src/commonTest/kotlin/com/harmony/kotlin/data/datasource/network/NetworkErrorMappingTests.kt

+8-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import com.harmony.kotlin.common.BaseTest
66
import com.harmony.kotlin.data.datasource.network.error.HttpException
77
import com.harmony.kotlin.data.error.DataNotFoundException
88
import com.harmony.kotlin.data.error.UnauthorizedException
9+
import kotlinx.coroutines.runBlocking
910
import kotlin.test.Test
1011
import kotlin.test.assertEquals
1112
import kotlin.test.assertFailsWith
@@ -15,10 +16,14 @@ class NetworkErrorMappingTests : BaseTest() {
1516

1617
private val apiMock: ApiMock = ApiMock()
1718

19+
// Workaround: Using runBlocking instead of runBlockingTest (used by our runTest) because of this issue:
20+
// - https://github.com/Kotlin/kotlinx.coroutines/issues/1222
21+
22+
1823
@Test
1924
fun `should throw UnauthorizedException when backend returns 401`() {
2025
assertFailsWith<UnauthorizedException> {
21-
runTest {
26+
runBlocking {
2227
apiMock.executeRequest(UnauthorizedRequest)
2328
}
2429
}
@@ -27,7 +32,7 @@ class NetworkErrorMappingTests : BaseTest() {
2732
@Test
2833
fun `should throw DataNotFound when backend returns 404`() {
2934
assertFailsWith<DataNotFoundException> {
30-
runTest {
35+
runBlocking {
3136
apiMock.executeRequest(NotFoundRequest)
3237
}
3338
}
@@ -36,7 +41,7 @@ class NetworkErrorMappingTests : BaseTest() {
3641
@Test
3742
fun `should throw HttpException when backend returns any 40X (minus 401 & 404) & 50X`() {
3843
try {
39-
runTest {
44+
runBlocking {
4045
apiMock.executeRequest(BadRequest)
4146
}
4247
} catch (e: HttpException) {

0 commit comments

Comments
 (0)