File tree Expand file tree Collapse file tree 1 file changed +10
-4
lines changed
src/commonTest/kotlin/com.adamratzman/spotify Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -42,17 +42,23 @@ suspend inline fun <reified T : Throwable> assertFailsWithSuspend(crossinline bl
42
42
}
43
43
}
44
44
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) {
46
48
withContext(Dispatchers .Default ) {
47
49
try {
48
50
block()
49
51
} catch (e: SpotifyException .BadRequestException ) {
50
52
// 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. " )
53
55
}
54
56
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;
56
62
}
57
63
}
58
64
}
You can’t perform that action at this time.
0 commit comments