Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,14 @@ internal class EventDataSource(
)
}

@Suppress("ThrowsCount")
private suspend fun handleWebSocketClosure(webSocketEvent: WebSocketEvent.Close<ConsumableNotificationResponse>) {
when (val cause = webSocketEvent.cause) {
null -> logger.i("Websocket closed normally")
null -> {
logger.i("Websocket closed normally, will retry to keep connection alive")
throw KaliumSyncException("Websocket closed normally", CoreFailure.Unknown(null))
}

is IOException ->
throw KaliumSyncException("Websocket disconnected", NetworkFailure.NoNetworkConnection(cause))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,32 @@ class EventRepositoryTest {
}
}

@Test
fun givenWebSocketClosedWithNullCause_whenHandlingClosure_thenShouldThrowKaliumSyncException() = runTest {
val (_, repository) = Arrangement()
.withClientHasConsumableNotifications(true)
.withCurrentClientIdReturning(TestClient.CLIENT_ID)
.withConsumeLiveEventsReturning(
NetworkResponse.Success(
value = flowOf(WebSocketEvent.Close(cause = null)),
headers = emptyMap(),
httpCode = 200
)
)
.arrange()

val eitherFlow = repository.liveEvents()
assertTrue(eitherFlow is Either.Right)

val flow = eitherFlow.value

val thrown = assertFailsWith<KaliumSyncException> {
flow.collect {}
}

assertIs<CoreFailure.Unknown>(thrown.coreFailureCause)
}

private companion object {
const val LAST_SAVED_EVENT_ID_KEY = "last_processed_event_id"
val MEMBER_JOIN_EVENT = EventContentDTO.Conversation.MemberJoinDTO(
Expand Down
Loading