Skip to content

Commit

Permalink
[CHA-RC2e] Update tests as per spec
Browse files Browse the repository at this point in the history
1. Fixed tests/roomtesthelper as per CHA-RC2e
  • Loading branch information
sacOO7 committed Dec 2, 2024
1 parent 73333df commit 274d226
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 34 deletions.
1 change: 1 addition & 0 deletions chat-android/src/main/java/com/ably/chat/Room.kt
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ internal class DefaultRoom(
init {
options.validateRoomOptions() // CHA-RC2a

// CHA-RC2e - Add contributors/features as per the order of precedence
val roomFeatures = mutableListOf<ContributesToRoomLifecycle>(messages)

options.presence?.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ fun createRoomFeatureMocks(roomId: String = DEFAULT_ROOM_ID, clientId: String =
val occupancyContributor = spyk(DefaultOccupancy(room), recordPrivateCalls = true)
val typingContributor = spyk(DefaultTyping(room), recordPrivateCalls = true)
val reactionsContributor = spyk(DefaultRoomReactions(room), recordPrivateCalls = true)
return listOf(messagesContributor, presenceContributor, occupancyContributor, typingContributor, reactionsContributor)

// CHA-RC2e - Add contributors/features as per the order of precedence
return listOf(messagesContributor, presenceContributor, typingContributor, reactionsContributor, occupancyContributor)
}

fun AblyRealtimeChannel.setState(state: ChannelState, errorInfo: ErrorInfo? = null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class AttachTest {
}

@Test
fun `(CHA-RL1f) Attach op should attach each contributor channel sequentially`() = runTest {
fun `(CHA-RL1f, CHA-RC2e) Attach op should attach each contributor channel sequentially`() = runTest {
val statusLifecycle = spyk(DefaultRoomLifecycle(logger))

mockkStatic(io.ably.lib.realtime.Channel::attachCoroutine)
Expand All @@ -190,9 +190,9 @@ class AttachTest {
}
Assert.assertEquals("1234::\$chat::\$chatMessages", capturedChannels[0].name)
Assert.assertEquals("1234::\$chat::\$chatMessages", capturedChannels[1].name)
Assert.assertEquals("1234::\$chat::\$chatMessages", capturedChannels[2].name)
Assert.assertEquals("1234::\$chat::\$typingIndicators", capturedChannels[3].name)
Assert.assertEquals("1234::\$chat::\$reactions", capturedChannels[4].name)
Assert.assertEquals("1234::\$chat::\$typingIndicators", capturedChannels[2].name)
Assert.assertEquals("1234::\$chat::\$reactions", capturedChannels[3].name)
Assert.assertEquals("1234::\$chat::\$chatMessages", capturedChannels[4].name)
}

@Test
Expand Down Expand Up @@ -346,7 +346,7 @@ class AttachTest {
}

@Test
fun `(CHA-RL1h5) When room enters failed state (CHA-RL1h4), room detach all channels not in failed state`() = runTest {
fun `(CHA-RL1h5, CHA-RC2e) When room enters failed state (CHA-RL1h4), room detach all channels not in failed state`() = runTest {
val statusLifecycle = spyk(DefaultRoomLifecycle(logger))

mockkStatic(io.ably.lib.realtime.Channel::attachCoroutine)
Expand Down Expand Up @@ -387,13 +387,13 @@ class AttachTest {

Assert.assertEquals("1234::\$chat::\$chatMessages", detachedChannels[0].name)
Assert.assertEquals("1234::\$chat::\$chatMessages", detachedChannels[1].name)
Assert.assertEquals("1234::\$chat::\$chatMessages", detachedChannels[2].name)
Assert.assertEquals("1234::\$chat::\$reactions", detachedChannels[3].name)
Assert.assertEquals("1234::\$chat::\$reactions", detachedChannels[2].name)
Assert.assertEquals("1234::\$chat::\$chatMessages", detachedChannels[3].name)
}

@Suppress("MaximumLineLength")
@Test
fun `(CHA-RL1h6) When room enters failed state, when CHA-RL1h5 fails to detach, op will be repeated till all channels are detached`() = runTest {
fun `(CHA-RL1h6, CHA-RC2e) When room enters failed state, when CHA-RL1h5 fails to detach, op will be repeated till all channels are detached`() = runTest {
val statusLifecycle = spyk(DefaultRoomLifecycle(logger))

mockkStatic(io.ably.lib.realtime.Channel::attachCoroutine)
Expand Down Expand Up @@ -439,7 +439,7 @@ class AttachTest {

Assert.assertEquals("1234::\$chat::\$chatMessages", detachedChannels[0].name)
Assert.assertEquals("1234::\$chat::\$chatMessages", detachedChannels[1].name)
Assert.assertEquals("1234::\$chat::\$chatMessages", detachedChannels[2].name)
Assert.assertEquals("1234::\$chat::\$reactions", detachedChannels[3].name)
Assert.assertEquals("1234::\$chat::\$reactions", detachedChannels[2].name)
Assert.assertEquals("1234::\$chat::\$chatMessages", detachedChannels[3].name)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class DetachTest {

@Suppress("MaximumLineLength")
@Test
fun `(CHA-RL2f, CHA-RL2g) Detach op should detach each contributor channel sequentially and room should be considered DETACHED`() = runTest {
fun `(CHA-RL2f, CHA-RL2g, CHA-RC2e) Detach op should detach each contributor channel sequentially and room should be considered DETACHED`() = runTest {
val statusLifecycle = spyk(DefaultRoomLifecycle(logger))

mockkStatic(io.ably.lib.realtime.Channel::detachCoroutine)
Expand All @@ -164,9 +164,9 @@ class DetachTest {
}
Assert.assertEquals("1234::\$chat::\$chatMessages", capturedChannels[0].name)
Assert.assertEquals("1234::\$chat::\$chatMessages", capturedChannels[1].name)
Assert.assertEquals("1234::\$chat::\$chatMessages", capturedChannels[2].name)
Assert.assertEquals("1234::\$chat::\$typingIndicators", capturedChannels[3].name)
Assert.assertEquals("1234::\$chat::\$reactions", capturedChannels[4].name)
Assert.assertEquals("1234::\$chat::\$typingIndicators", capturedChannels[2].name)
Assert.assertEquals("1234::\$chat::\$reactions", capturedChannels[3].name)
Assert.assertEquals("1234::\$chat::\$chatMessages", capturedChannels[4].name)

assertWaiter { roomLifecycle.atomicCoroutineScope().finishedProcessing }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,9 @@ class ReleaseTest {
}
}

@Suppress("MaximumLineLength")
@Test
fun `(CHA-RL3d) Release op should detach each contributor channel sequentially and room should be considered RELEASED`() = runTest {
fun `(CHA-RL3d, CHA-RC2e) Release op should detach each contributor channel sequentially and room should be considered RELEASED`() = runTest {
val statusLifecycle = spyk(DefaultRoomLifecycle(logger)).apply {
setStatus(RoomStatus.Attached)
}
Expand All @@ -146,15 +147,15 @@ class ReleaseTest {
}
Assert.assertEquals("1234::\$chat::\$chatMessages", capturedChannels[0].name)
Assert.assertEquals("1234::\$chat::\$chatMessages", capturedChannels[1].name)
Assert.assertEquals("1234::\$chat::\$chatMessages", capturedChannels[2].name)
Assert.assertEquals("1234::\$chat::\$typingIndicators", capturedChannels[3].name)
Assert.assertEquals("1234::\$chat::\$reactions", capturedChannels[4].name)
Assert.assertEquals("1234::\$chat::\$typingIndicators", capturedChannels[2].name)
Assert.assertEquals("1234::\$chat::\$reactions", capturedChannels[3].name)
Assert.assertEquals("1234::\$chat::\$chatMessages", capturedChannels[4].name)

assertWaiter { roomLifecycle.atomicCoroutineScope().finishedProcessing }
}

@Test
fun `(CHA-RL3e) If a one of the contributors is in failed state, release op continues for other contributors`() = runTest {
fun `(CHA-RL3e, CHA-RC2e) If a one of the contributors is in failed state, release op continues for other contributors`() = runTest {
val statusLifecycle = spyk(DefaultRoomLifecycle(logger)).apply {
setStatus(RoomStatus.Attached)
}
Expand Down Expand Up @@ -183,8 +184,8 @@ class ReleaseTest {
Assert.assertEquals(4, capturedChannels.size)
Assert.assertEquals("1234::\$chat::\$chatMessages", capturedChannels[0].name)
Assert.assertEquals("1234::\$chat::\$chatMessages", capturedChannels[1].name)
Assert.assertEquals("1234::\$chat::\$chatMessages", capturedChannels[2].name)
Assert.assertEquals("1234::\$chat::\$reactions", capturedChannels[3].name)
Assert.assertEquals("1234::\$chat::\$reactions", capturedChannels[2].name)
Assert.assertEquals("1234::\$chat::\$chatMessages", capturedChannels[3].name)
}

@Test
Expand Down Expand Up @@ -228,7 +229,7 @@ class ReleaseTest {
}

@Test
fun `(CHA-RL3g) Release op continues till all contributors enters either DETACHED or FAILED state`() = runTest {
fun `(CHA-RL3g, CHA-RC2e) Release op continues till all contributors enters either DETACHED or FAILED state`() = runTest {
val statusLifecycle = spyk(DefaultRoomLifecycle(logger)).apply {
setStatus(RoomStatus.Attached)
}
Expand Down Expand Up @@ -261,9 +262,9 @@ class ReleaseTest {
}
Assert.assertEquals("1234::\$chat::\$chatMessages", capturedChannels[0].name)
Assert.assertEquals("1234::\$chat::\$chatMessages", capturedChannels[1].name)
Assert.assertEquals("1234::\$chat::\$chatMessages", capturedChannels[2].name)
Assert.assertEquals("1234::\$chat::\$typingIndicators", capturedChannels[3].name)
Assert.assertEquals("1234::\$chat::\$reactions", capturedChannels[4].name)
Assert.assertEquals("1234::\$chat::\$typingIndicators", capturedChannels[2].name)
Assert.assertEquals("1234::\$chat::\$reactions", capturedChannels[3].name)
Assert.assertEquals("1234::\$chat::\$chatMessages", capturedChannels[4].name)

assertWaiter { roomLifecycle.atomicCoroutineScope().finishedProcessing }

Expand All @@ -273,8 +274,9 @@ class ReleaseTest {
}
}

@Suppress("MaximumLineLength")
@Test
fun `(CHA-RL3h) Upon channel release, underlying Realtime Channels are released from the core SDK prevent leakage`() = runTest {
fun `(CHA-RL3h, CHA-RC2e) Upon channel release, underlying Realtime Channels are released from the core SDK prevent leakage`() = runTest {
val statusLifecycle = spyk(DefaultRoomLifecycle(logger)).apply {
setStatus(RoomStatus.Attached)
}
Expand Down Expand Up @@ -306,9 +308,9 @@ class ReleaseTest {
}
Assert.assertEquals("1234::\$chat::\$chatMessages", releasedChannels[0].name)
Assert.assertEquals("1234::\$chat::\$chatMessages", releasedChannels[1].name)
Assert.assertEquals("1234::\$chat::\$chatMessages", releasedChannels[2].name)
Assert.assertEquals("1234::\$chat::\$typingIndicators", releasedChannels[3].name)
Assert.assertEquals("1234::\$chat::\$reactions", releasedChannels[4].name)
Assert.assertEquals("1234::\$chat::\$typingIndicators", releasedChannels[2].name)
Assert.assertEquals("1234::\$chat::\$reactions", releasedChannels[3].name)
Assert.assertEquals("1234::\$chat::\$chatMessages", releasedChannels[4].name)

assertWaiter { roomLifecycle.atomicCoroutineScope().finishedProcessing }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class RetryTest {

@Suppress("MaximumLineLength")
@Test
fun `(CHA-RL5f) If, during the CHA-RL5d wait, the contributor channel becomes ATTACHED, then attach operation continues for other contributors as per CHA-RL1e`() = runTest {
fun `(CHA-RL5f, CHA-RC2e) If, during the CHA-RL5d wait, the contributor channel becomes ATTACHED, then attach operation continues for other contributors as per CHA-RL1e`() = runTest {
val statusLifecycle = spyk(DefaultRoomLifecycle(logger))

mockkStatic(io.ably.lib.realtime.Channel::attachCoroutine)
Expand Down Expand Up @@ -237,9 +237,9 @@ class RetryTest {

Assert.assertEquals("1234::\$chat::\$chatMessages", capturedAttachedChannels[0].name)
Assert.assertEquals("1234::\$chat::\$chatMessages", capturedAttachedChannels[1].name)
Assert.assertEquals("1234::\$chat::\$chatMessages", capturedAttachedChannels[2].name)
Assert.assertEquals("1234::\$chat::\$typingIndicators", capturedAttachedChannels[3].name)
Assert.assertEquals("1234::\$chat::\$reactions", capturedAttachedChannels[4].name)
Assert.assertEquals("1234::\$chat::\$typingIndicators", capturedAttachedChannels[2].name)
Assert.assertEquals("1234::\$chat::\$reactions", capturedAttachedChannels[3].name)
Assert.assertEquals("1234::\$chat::\$chatMessages", capturedAttachedChannels[4].name)

assertWaiter { roomLifecycle.atomicCoroutineScope().finishedProcessing }
}
Expand Down

0 comments on commit 274d226

Please sign in to comment.