fix(chat): DM SSE read timeout을 제거한다

This commit is contained in:
2026-06-11 12:05:39 +09:00
parent 0263e64f40
commit 841ed5f6f8
2 changed files with 43 additions and 1 deletions

View File

@@ -8,6 +8,7 @@ import okhttp3.OkHttpClient
import okhttp3.Request import okhttp3.Request
import okhttp3.Response import okhttp3.Response
import java.io.IOException import java.io.IOException
import java.util.concurrent.TimeUnit
class DmChatEventParser(private val gson: Gson) { class DmChatEventParser(private val gson: Gson) {
sealed class Event { sealed class Event {
@@ -60,7 +61,7 @@ interface DmChatRealtimeClient {
} }
class DmChatEventClient( class DmChatEventClient(
private val okHttpClient: OkHttpClient, okHttpClient: OkHttpClient,
gson: Gson, gson: Gson,
private val baseUrl: String private val baseUrl: String
) : DmChatRealtimeClient { ) : DmChatRealtimeClient {
@@ -70,6 +71,9 @@ class DmChatEventClient(
fun onFailure(throwable: Throwable) fun onFailure(throwable: Throwable)
} }
private val okHttpClient = okHttpClient.newBuilder()
.readTimeout(0, TimeUnit.MILLISECONDS)
.build()
private val parser = DmChatEventParser(gson) private val parser = DmChatEventParser(gson)
private var call: Call? = null private var call: Call? = null

View File

@@ -10,6 +10,7 @@ import okhttp3.Response
import okhttp3.ResponseBody.Companion.toResponseBody import okhttp3.ResponseBody.Companion.toResponseBody
import org.junit.Assert.assertEquals import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotNull import org.junit.Assert.assertNotNull
import org.junit.Assert.assertTrue
import org.junit.Test import org.junit.Test
import java.util.concurrent.CountDownLatch import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
@@ -91,6 +92,43 @@ class DmChatEventClientTest {
assertEquals("SSE stream closed", failure?.message) 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( private fun clientWithResponse(
code: Int, code: Int,
body: String body: String