Fix HermesWsClientTest teardown and OkHttp 5.x deprecation warnings
- Widen catch in tearDown() from Exception to Throwable so MockWebServer.shutdown() AssertionError is caught (OkHttp 5.x enforces clean connection state on shutdown) - Increase teardown wait from 100ms to 500ms for WS close handshake - Replace deprecated RequestBody.create(null, ...) with toRequestBody() extension from Kotlin API
This commit is contained in:
1 parent
3128d63bb2
commit
82bd98dfd8
3 files changed
+9
-6
No files matched your search
@@ -25,7 +25,9 @@ import kotlinx.coroutines.launch
|
||||
import okhttp3.CertificatePinner
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
import okhttp3.MediaType.Companion.toMediaType
|
||||
import okhttp3.RequestBody
|
||||
import okhttp3.RequestBody.Companion.toRequestBody
|
||||
import okhttp3.Response
|
||||
import okhttp3.WebSocket
|
||||
import okhttp3.WebSocketListener
|
||||
@@ -166,7 +168,7 @@ object HermesWsClient {
|
||||
Request.Builder()
|
||||
.url("http://${AuthManager.getHost()}:${AuthManager.getPort()}/api/auth/ws-ticket")
|
||||
.header("Cookie", "hermes_session_at=$sessionCookie")
|
||||
.post(RequestBody.create(null, "{}"))
|
||||
.post("{}".toRequestBody())
|
||||
.build()
|
||||
val response = client.newCall(request).execute()
|
||||
if (response.isSuccessful) {
|
||||
|
||||
@@ -18,7 +18,7 @@ import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
import okhttp3.RequestBody
|
||||
import okhttp3.RequestBody.Companion.toRequestBody
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
/**
|
||||
@@ -341,7 +341,7 @@ class AuthLoginViewModel(private val app: Application) : ViewModel() {
|
||||
Request.Builder()
|
||||
.url("$baseUrl/auth/password-login")
|
||||
.header("Content-Type", "application/json")
|
||||
.post(RequestBody.create(null, jsonBody))
|
||||
.post(jsonBody.toRequestBody())
|
||||
.build()
|
||||
val loginResp = loginClient.newCall(loginReq).execute()
|
||||
|
||||
@@ -389,7 +389,7 @@ class AuthLoginViewModel(private val app: Application) : ViewModel() {
|
||||
Request.Builder()
|
||||
.url("$baseUrl/api/auth/ws-ticket")
|
||||
.header("Cookie", cookieHeader)
|
||||
.post(RequestBody.create(null, "{}"))
|
||||
.post("{}".toRequestBody())
|
||||
.build()
|
||||
val ticketResp = ticketClient.newCall(ticketReq).execute()
|
||||
|
||||
|
||||
@@ -60,10 +60,11 @@ class HermesWsClientTest {
|
||||
fun tearDown() {
|
||||
HermesWsClient.disconnect()
|
||||
// Wait a bit to allow internal OkHttp coroutines to clean up before shutting down MockWebServer
|
||||
Thread.sleep(100)
|
||||
// Increased from 100ms for OkHttp 5.x — needs more time for the WS close handshake
|
||||
Thread.sleep(500)
|
||||
try {
|
||||
mockWebServer.shutdown()
|
||||
} catch (e: Exception) {
|
||||
} catch (e: Throwable) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
unmockkAll()
|
||||
|
||||
Reference in new issue
Block a user