Skip to content

Commit 0722b0f

Browse files
committed
test: another attempt to fix the flaky token related tests
1 parent 4fb7e24 commit 0722b0f

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

model-client/src/jvmMain/kotlin/org/modelix/model/oauth/ModelixAuthClient.kt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import kotlinx.coroutines.launch
3535
import kotlinx.coroutines.withContext
3636
import org.modelix.kotlin.utils.urlEncode
3737
import java.net.SocketException
38+
import java.net.SocketTimeoutException
3839

3940
@Suppress("UndocumentedPublicClass") // already documented in the expected declaration
4041
actual class ModelixAuthClient {
@@ -62,11 +63,16 @@ actual class ModelixAuthClient {
6263
}
6364

6465
fun Credential.alwaysRefresh(): Credential? {
65-
try {
66-
val success = refreshToken()
67-
if (success) return this
68-
} catch (e: TokenResponseException) {
69-
LOG.warn("Could not refresh the access token: ${e.details}")
66+
for (attempt in 1..3) {
67+
try {
68+
val success = refreshToken()
69+
if (success) return this
70+
} catch (e: SocketTimeoutException) {
71+
LOG.warn(e) { "Token refresh timed out" }
72+
} catch (e: TokenResponseException) {
73+
LOG.warn("Could not refresh the access token: ${e.details}")
74+
break
75+
}
7076
}
7177
return null
7278
}

0 commit comments

Comments
 (0)