Skip to content

Commit 5260e66

Browse files
committed
retry failed tests
1 parent 06ad192 commit 5260e66

File tree

1 file changed

+10
-4
lines changed
  • src/commonTest/kotlin/com.adamratzman/spotify

1 file changed

+10
-4
lines changed

src/commonTest/kotlin/com.adamratzman/spotify/Common.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,23 @@ suspend inline fun <reified T : Throwable> assertFailsWithSuspend(crossinline bl
4242
}
4343
}
4444

45-
fun <T> runTestOnDefaultDispatcher(block: suspend CoroutineScope.() -> T): TestResult = runTest(timeout = 60.seconds) {
45+
fun <T> runTestOnDefaultDispatcher(block: suspend CoroutineScope.() -> T): TestResult = runTestOnDefaultDispatcher(block, shouldRetry = true)
46+
47+
fun <T> runTestOnDefaultDispatcher(block: suspend CoroutineScope.() -> T, shouldRetry: Boolean): TestResult = runTest(timeout = 60.seconds) {
4648
withContext(Dispatchers.Default) {
4749
try {
4850
block()
4951
} catch (e: SpotifyException.BadRequestException) {
5052
// we shouldn't fail just because we received a 5xx from spotify
51-
if (e.statusCode !in 500..599) {
52-
throw e;
53+
if (e.statusCode in 500..599) {
54+
println("Received 5xx for block.")
5355
}
5456

55-
println("Received 5xx for block.")
57+
if (shouldRetry) runTestOnDefaultDispatcher(block, shouldRetry = false)
58+
else throw e;
59+
} catch (e: Exception) {
60+
if (shouldRetry) runTestOnDefaultDispatcher(block, shouldRetry = false)
61+
else throw e;
5662
}
5763
}
5864
}

0 commit comments

Comments
 (0)