From 274d226301cf253a6a04bb2c104981ace1cdcd37 Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Mon, 2 Dec 2024 20:07:59 +0530 Subject: [PATCH] [CHA-RC2e] Update tests as per spec 1. Fixed tests/roomtesthelper as per CHA-RC2e --- .../src/main/java/com/ably/chat/Room.kt | 1 + .../com/ably/chat/room/RoomTestHelpers.kt | 4 ++- .../ably/chat/room/lifecycle/AttachTest.kt | 20 ++++++------ .../ably/chat/room/lifecycle/DetachTest.kt | 8 ++--- .../ably/chat/room/lifecycle/ReleaseTest.kt | 32 ++++++++++--------- .../com/ably/chat/room/lifecycle/RetryTest.kt | 8 ++--- 6 files changed, 39 insertions(+), 34 deletions(-) diff --git a/chat-android/src/main/java/com/ably/chat/Room.kt b/chat-android/src/main/java/com/ably/chat/Room.kt index a99bc4fd..4d394d0d 100644 --- a/chat-android/src/main/java/com/ably/chat/Room.kt +++ b/chat-android/src/main/java/com/ably/chat/Room.kt @@ -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(messages) options.presence?.let { diff --git a/chat-android/src/test/java/com/ably/chat/room/RoomTestHelpers.kt b/chat-android/src/test/java/com/ably/chat/room/RoomTestHelpers.kt index 2658daa8..a550efbc 100644 --- a/chat-android/src/test/java/com/ably/chat/room/RoomTestHelpers.kt +++ b/chat-android/src/test/java/com/ably/chat/room/RoomTestHelpers.kt @@ -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) { diff --git a/chat-android/src/test/java/com/ably/chat/room/lifecycle/AttachTest.kt b/chat-android/src/test/java/com/ably/chat/room/lifecycle/AttachTest.kt index 9faf157f..022a1078 100644 --- a/chat-android/src/test/java/com/ably/chat/room/lifecycle/AttachTest.kt +++ b/chat-android/src/test/java/com/ably/chat/room/lifecycle/AttachTest.kt @@ -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) @@ -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 @@ -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) @@ -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) @@ -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) } } diff --git a/chat-android/src/test/java/com/ably/chat/room/lifecycle/DetachTest.kt b/chat-android/src/test/java/com/ably/chat/room/lifecycle/DetachTest.kt index 256bbf5c..d9660ec6 100644 --- a/chat-android/src/test/java/com/ably/chat/room/lifecycle/DetachTest.kt +++ b/chat-android/src/test/java/com/ably/chat/room/lifecycle/DetachTest.kt @@ -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) @@ -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 } } diff --git a/chat-android/src/test/java/com/ably/chat/room/lifecycle/ReleaseTest.kt b/chat-android/src/test/java/com/ably/chat/room/lifecycle/ReleaseTest.kt index 5f70b4f8..ce9e890a 100644 --- a/chat-android/src/test/java/com/ably/chat/room/lifecycle/ReleaseTest.kt +++ b/chat-android/src/test/java/com/ably/chat/room/lifecycle/ReleaseTest.kt @@ -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) } @@ -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) } @@ -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 @@ -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) } @@ -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 } @@ -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) } @@ -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 } diff --git a/chat-android/src/test/java/com/ably/chat/room/lifecycle/RetryTest.kt b/chat-android/src/test/java/com/ably/chat/room/lifecycle/RetryTest.kt index edfcafc4..b1caf3cd 100644 --- a/chat-android/src/test/java/com/ably/chat/room/lifecycle/RetryTest.kt +++ b/chat-android/src/test/java/com/ably/chat/room/lifecycle/RetryTest.kt @@ -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) @@ -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 } }