fix(chat): DM SSE read timeout을 제거한다
This commit is contained in:
@@ -8,6 +8,7 @@ import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
import okhttp3.Response
|
||||
import java.io.IOException
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
class DmChatEventParser(private val gson: Gson) {
|
||||
sealed class Event {
|
||||
@@ -60,7 +61,7 @@ interface DmChatRealtimeClient {
|
||||
}
|
||||
|
||||
class DmChatEventClient(
|
||||
private val okHttpClient: OkHttpClient,
|
||||
okHttpClient: OkHttpClient,
|
||||
gson: Gson,
|
||||
private val baseUrl: String
|
||||
) : DmChatRealtimeClient {
|
||||
@@ -70,6 +71,9 @@ class DmChatEventClient(
|
||||
fun onFailure(throwable: Throwable)
|
||||
}
|
||||
|
||||
private val okHttpClient = okHttpClient.newBuilder()
|
||||
.readTimeout(0, TimeUnit.MILLISECONDS)
|
||||
.build()
|
||||
private val parser = DmChatEventParser(gson)
|
||||
private var call: Call? = null
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import okhttp3.Response
|
||||
import okhttp3.ResponseBody.Companion.toResponseBody
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNotNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import java.util.concurrent.CountDownLatch
|
||||
import java.util.concurrent.TimeUnit
|
||||
@@ -91,6 +92,43 @@ class DmChatEventClientTest {
|
||||
assertEquals("SSE stream closed", failure?.message)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `SSE 전용 client는 공유 client의 read timeout을 제거한다`() {
|
||||
val requestLatch = CountDownLatch(1)
|
||||
var requestReadTimeoutMillis: Int? = null
|
||||
val baseClient = OkHttpClient.Builder()
|
||||
.readTimeout(60, TimeUnit.SECONDS)
|
||||
.addInterceptor { chain ->
|
||||
requestReadTimeoutMillis = chain.readTimeoutMillis()
|
||||
requestLatch.countDown()
|
||||
Response.Builder()
|
||||
.request(chain.request())
|
||||
.protocol(Protocol.HTTP_1_1)
|
||||
.code(200)
|
||||
.message("test")
|
||||
.body("event: connected\n\n".toResponseBody("text/event-stream".toMediaType()))
|
||||
.build()
|
||||
}
|
||||
.build()
|
||||
|
||||
val client = DmChatEventClient(
|
||||
okHttpClient = baseClient,
|
||||
gson = Gson(),
|
||||
baseUrl = "https://example.com"
|
||||
)
|
||||
|
||||
client.connect(
|
||||
token = "test-token",
|
||||
roomId = 10L,
|
||||
listener = TestListener()
|
||||
)
|
||||
|
||||
assertTrue(requestLatch.await(2, TimeUnit.SECONDS))
|
||||
|
||||
assertEquals(60_000, baseClient.readTimeoutMillis)
|
||||
assertEquals(0, requestReadTimeoutMillis)
|
||||
}
|
||||
|
||||
private fun clientWithResponse(
|
||||
code: Int,
|
||||
body: String
|
||||
|
||||
Reference in New Issue
Block a user