1package soy.iko.opencode.data.network
3import io.ktor.client.HttpClient
4import io.ktor.client.engine.mock.MockEngine
5import io.ktor.client.engine.mock.respondError
6import io.ktor.client.plugins.sse.SSE
7import io.ktor.http.HttpStatusCode
8import kotlinx.coroutines.ExperimentalCoroutinesApi
9import kotlinx.coroutines.cancel
10import org.junit.Assert.assertEquals
13@OptIn(ExperimentalCoroutinesApi::class)
14class EventStreamClientTest {
17 * The SSE plugin requires a streaming response body which MockEngine can't provide,
18 * so full SSE integration isn't testable in pure JVM tests. The reconnect/backoff
19 * logic is covered by [WithRetryTest] (same exponential-backoff formula) and the
20 * event decoding is covered by [OpencodeJsonTest]. Here we verify only the initial
21 * state — the connection-state machine starts in Disconnected.
24 fun stateIsDisconnectedBeforeSubscribing() {
25 val engine = MockEngine { respondError(HttpStatusCode.InternalServerError) }
26 val client = HttpClient(engine) { install(SSE) }
27 val scope = kotlinx.coroutines.CoroutineScope(
28 kotlinx.coroutines.SupervisorJob() + kotlinx.coroutines.Dispatchers.Unconfined,
30 val sse = EventStreamClient(client, scope)
32 assertEquals(EventStreamClient.ConnectionState.Disconnected, sse.state.value)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list