feat: optimize network stack (#404)
* feat: optimize network stack and connection management Refactor OkHttp connection pools, consolidate Gson serialization, add network-aware WebSocket reconnects, and deduplicate concurrent requests. * test: update mapping assertions for AuthExpired * refactor: address PR review feedback on network stack Simplify health check, improve authenticator cookie matching robustness, resolve nit imports, and add unit tests.
This commit is contained in:
19 files changed
+455
-206
No files matched your search
@@ -15,7 +15,6 @@ class NetworkResultTest {
|
||||
val codesAndExpectedMessages =
|
||||
mapOf(
|
||||
400 to "Bad Request (HTTP 400): The server could not understand the request.",
|
||||
401 to "Unauthorized (HTTP 401): Authentication token is invalid or expired.",
|
||||
403 to "Forbidden (HTTP 403): You do not have permission to access this resource.",
|
||||
404 to "Not Found (HTTP 404): The requested resource could not be found.",
|
||||
405 to "Method Not Allowed (HTTP 405).",
|
||||
@@ -35,6 +34,13 @@ class NetworkResultTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMapHttpError_authExpired() {
|
||||
val error = mapHttpError(401)
|
||||
assertTrue(error is NetworkError.AuthExpired)
|
||||
assertEquals("Authentication token has expired. Please log in again.", error.message)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMapHttpError_unknownCode() {
|
||||
val error = mapHttpError(418)
|
||||
@@ -44,6 +50,24 @@ class NetworkResultTest {
|
||||
assertEquals("HTTP Error 418: Unexpected server response.", error.message)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testIsRetryable() {
|
||||
assertTrue(!isRetryable(java.net.UnknownHostException("Host not found")))
|
||||
assertTrue(!isRetryable(javax.net.ssl.SSLException("SSL failed")))
|
||||
assertTrue(isRetryable(java.net.ConnectException("Connection refused")))
|
||||
assertTrue(isRetryable(java.net.SocketTimeoutException("Timeout")))
|
||||
assertTrue(isRetryable(IOException("Generic IO error")))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testJitteredBackoff() {
|
||||
val baseMs = 1000L
|
||||
for (i in 0..100) {
|
||||
val backoff = jitteredBackoff(baseMs)
|
||||
assertTrue(backoff in 750..1250)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSafeApiCall_successWithBody() =
|
||||
runBlocking {
|
||||
|
||||
Reference in new issue
Block a user