Skip to content

Commit

Permalink
Merge branch 'feature/roomlifecycle-detach-with-retry' into tests/roo…
Browse files Browse the repository at this point in the history
…mlifecycle-detach
  • Loading branch information
sacOO7 committed Nov 22, 2024
2 parents cc4b259 + ed090c6 commit 64cb73e
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions chat-android/src/test/java/com/ably/chat/room/AttachTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.ably.chat.room

import com.ably.chat.DefaultRoomLifecycle
import com.ably.chat.ErrorCodes
import com.ably.chat.HttpStatusCodes
import com.ably.chat.ResolvedContributor
import com.ably.chat.RoomLifecycleManager
import com.ably.chat.RoomStatus
Expand Down Expand Up @@ -47,17 +48,18 @@ class AttachTest {
)

@Test
fun `(CHA-RL1a) Attach success when channel in already in attached state`() = runTest {
fun `(CHA-RL1a) Attach success when room is already in attached state`() = runTest {
val statusLifecycle = spyk<DefaultRoomLifecycle>().apply {
setStatus(RoomStatus.Attached)
}
val roomLifecycle = spyk(RoomLifecycleManager(roomScope, statusLifecycle, createRoomFeatureMocks()))
val result = kotlin.runCatching { roomLifecycle.attach() }
Assert.assertTrue(result.isSuccess)
assertWaiter { roomLifecycle.atomicCoroutineScope().finishedProcessing }
}

@Test
fun `(CHA-RL1b) Attach throws exception when channel in releasing state`() = runTest {
fun `(CHA-RL1b) Attach throws exception when room in releasing state`() = runTest {
val statusLifecycle = spyk<DefaultRoomLifecycle>().apply {
setStatus(RoomStatus.Releasing)
}
Expand All @@ -68,12 +70,13 @@ class AttachTest {
}
}
Assert.assertEquals("unable to attach room; room is releasing", exception.errorInfo.message)
Assert.assertEquals(102_102, exception.errorInfo.code)
Assert.assertEquals(500, exception.errorInfo.statusCode)
Assert.assertEquals(ErrorCodes.RoomIsReleasing.errorCode, exception.errorInfo.code)
Assert.assertEquals(HttpStatusCodes.InternalServerError, exception.errorInfo.statusCode)
assertWaiter { roomLifecycle.atomicCoroutineScope().finishedProcessing }
}

@Test
fun `(CHA-RL1c) Attach throws exception when channel in released state`() = runTest {
fun `(CHA-RL1c) Attach throws exception when room in released state`() = runTest {
val statusLifecycle = spyk<DefaultRoomLifecycle>().apply {
setStatus(RoomStatus.Released)
}
Expand All @@ -84,8 +87,9 @@ class AttachTest {
}
}
Assert.assertEquals("unable to attach room; room is released", exception.errorInfo.message)
Assert.assertEquals(102_103, exception.errorInfo.code)
Assert.assertEquals(500, exception.errorInfo.statusCode)
Assert.assertEquals(ErrorCodes.RoomIsReleased.errorCode, exception.errorInfo.code)
Assert.assertEquals(HttpStatusCodes.InternalServerError, exception.errorInfo.statusCode)
assertWaiter { roomLifecycle.atomicCoroutineScope().finishedProcessing }
}

@Test
Expand Down Expand Up @@ -128,8 +132,9 @@ class AttachTest {
val exception = result.exceptionOrNull() as AblyException

Assert.assertEquals("unable to attach room; room is released", exception.errorInfo.message)
Assert.assertEquals(102_103, exception.errorInfo.code)
Assert.assertEquals(500, exception.errorInfo.statusCode)
Assert.assertEquals(ErrorCodes.RoomIsReleased.errorCode, exception.errorInfo.code)
Assert.assertEquals(HttpStatusCodes.InternalServerError, exception.errorInfo.statusCode)
assertWaiter { roomLifecycle.atomicCoroutineScope().finishedProcessing }

coVerify { roomLifecycle.release() }
}
Expand All @@ -143,6 +148,7 @@ class AttachTest {
}
val roomLifecycle = spyk(RoomLifecycleManager(roomScope, statusLifecycle, emptyList()))
roomLifecycle.attach()

Assert.assertEquals(RoomStatus.Attaching, roomStatusChanges[0].current)
Assert.assertEquals(RoomStatus.Attached, roomStatusChanges[1].current)
assertWaiter { roomLifecycle.atomicCoroutineScope().finishedProcessing }
Expand Down Expand Up @@ -203,7 +209,6 @@ class AttachTest {
}
justRun { roomLifecycle invokeNoArgs "clearAllTransientDetachTimeouts" }

roomLifecycle.attach()
val result = kotlin.runCatching { roomLifecycle.attach() }

// CHA-RL1g1
Expand Down

0 comments on commit 64cb73e

Please sign in to comment.