File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed
commonMain/kotlin/com/wire/kalium/logic/data/event
commonTest/kotlin/com/wire/kalium/logic/data/event Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -353,9 +353,14 @@ internal class EventDataSource(
353353 )
354354 }
355355
356+ @Suppress(" ThrowsCount" )
356357 private suspend fun handleWebSocketClosure (webSocketEvent : WebSocketEvent .Close <ConsumableNotificationResponse >) {
357358 when (val cause = webSocketEvent.cause) {
358- null -> logger.i(" Websocket closed normally" )
359+ null -> {
360+ logger.i(" Websocket closed normally, will retry to keep connection alive" )
361+ throw KaliumSyncException (" Websocket closed normally" , CoreFailure .Unknown (null ))
362+ }
363+
359364 is IOException ->
360365 throw KaliumSyncException (" Websocket disconnected" , NetworkFailure .NoNetworkConnection (cause))
361366
Original file line number Diff line number Diff line change @@ -585,6 +585,32 @@ class EventRepositoryTest {
585585 }
586586 }
587587
588+ @Test
589+ fun givenWebSocketClosedWithNullCause_whenHandlingClosure_thenShouldThrowKaliumSyncException () = runTest {
590+ val (_, repository) = Arrangement ()
591+ .withClientHasConsumableNotifications(true )
592+ .withCurrentClientIdReturning(TestClient .CLIENT_ID )
593+ .withConsumeLiveEventsReturning(
594+ NetworkResponse .Success (
595+ value = flowOf(WebSocketEvent .Close (cause = null )),
596+ headers = emptyMap(),
597+ httpCode = 200
598+ )
599+ )
600+ .arrange()
601+
602+ val eitherFlow = repository.liveEvents()
603+ assertTrue(eitherFlow is Either .Right )
604+
605+ val flow = eitherFlow.value
606+
607+ val thrown = assertFailsWith<KaliumSyncException > {
608+ flow.collect {}
609+ }
610+
611+ assertIs<CoreFailure .Unknown >(thrown.coreFailureCause)
612+ }
613+
588614 private companion object {
589615 const val LAST_SAVED_EVENT_ID_KEY = " last_processed_event_id"
590616 val MEMBER_JOIN_EVENT = EventContentDTO .Conversation .MemberJoinDTO (
You can’t perform that action at this time.
0 commit comments