-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ECO-5009][CHA-RL1] RoomLifecycle ATTACH tests #37
Open
sacOO7
wants to merge
21
commits into
feature/roomlifecycle-attach-with-retry
Choose a base branch
from
tests/roomlifecycle-attach
base: feature/roomlifecycle-attach-with-retry
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
d990bd6
Added basic unit tests for room lifecyclemanager attach
sacOO7 0a6a45e
Merge branch 'feature/roomlifecycle-attach-with-retry' into tests/roo…
sacOO7 983ec92
Fixed RoomLifecycleManagerTest, added sequentialRoomScope property to…
sacOO7 18cc65d
Marked atomicCoroutineScope as internal to access from tests, added e…
sacOO7 30ad922
Refactored RoomLifecycleManagerTest, added more assertions for CHA-RL1d
sacOO7 0a9d391
Marked atomicCoroutineScope as private, accessed via reflection+exten…
sacOO7 52005c0
Bumped up io.mocck test dependency to latest version
sacOO7 b6f4dbd
Added channel attach room lifecycle spec CHA-RL1f, CHA-RL1g, updated
sacOO7 1d92116
Added mising unit test case blocks for channel attach
sacOO7 29a9782
Added test for spec CHA-RL1h1 channel attach, improved exception hand…
sacOO7 0f400b1
Merge branch 'feature/roomlifecycle-attach-with-retry' into tests/roo…
sacOO7 54a01c3
Refactored roomLifeCycle ATTACH tests with respective spec
sacOO7 2fee93d
Added channel attach retry test as per spec CHA-RL1h3
sacOO7 e6b46ff
Added channel attach unit test for contributor failure, get all remai…
sacOO7 f097e96
Added channel attach failure test, retry channel detach remaining cha…
sacOO7 e73b9ba
Annotated RoomLifeCycleManager code with right spec tags, refactored …
sacOO7 a9fffc2
Merge branch 'feature/roomlifecycle-attach-with-retry' into tests/roo…
sacOO7 774cc3b
Fixed linting issues for roomlifecycle attach tests
sacOO7 4fc33c7
Merge branch 'feature/roomlifecycle-attach-with-retry' into tests/roo…
sacOO7 097e82c
Added detach delay to fix test flakiness for channel detach
sacOO7 f4883bc
Refactored room attach tests with proper naming convention,
sacOO7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
chat-android/src/test/java/com/ably/chat/RoomLifecycleManagerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.ably.chat | ||
|
||
import io.ably.lib.types.AblyException | ||
import io.mockk.spyk | ||
import kotlinx.coroutines.CoroutineName | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.runBlocking | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.Assert | ||
import org.junit.Test | ||
|
||
class RoomLifecycleManagerTest { | ||
|
||
private val roomScope = CoroutineScope( | ||
Dispatchers.Default.limitedParallelism(1) + CoroutineName("roomId"), | ||
) | ||
|
||
@Test | ||
fun `(CHA-RL1a) Attach return when channel in already in attached state`() = runTest { | ||
val status = spyk<DefaultStatus>().apply { | ||
setStatus(RoomLifecycle.Attached) | ||
} | ||
val roomLifecycle = spyk(RoomLifecycleManager(roomScope, status, listOf())) | ||
val result = kotlin.runCatching { roomLifecycle.attach() } | ||
Assert.assertTrue(result.isSuccess) | ||
} | ||
|
||
@Test | ||
fun `(CHA-RL1b) Attach return when channel in releasing state`() = runTest { | ||
val status = spyk<DefaultStatus>().apply { | ||
setStatus(RoomLifecycle.Releasing) | ||
} | ||
val roomLifecycle = spyk(RoomLifecycleManager(roomScope, status, listOf())) | ||
val exception = Assert.assertThrows(AblyException::class.java) { | ||
runBlocking { | ||
roomLifecycle.attach() | ||
} | ||
} | ||
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) | ||
} | ||
|
||
@Test | ||
fun `(CHA-RL1c) Attach return when channel in released state`() = runTest { | ||
val status = spyk<DefaultStatus>().apply { | ||
setStatus(RoomLifecycle.Released) | ||
} | ||
val roomLifecycle = spyk(RoomLifecycleManager(roomScope, status, listOf())) | ||
val exception = Assert.assertThrows(AblyException::class.java) { | ||
runBlocking { | ||
roomLifecycle.attach() | ||
} | ||
} | ||
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) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Add Test Lifecycle Management Across Test Files
Multiple test files define
roomScope
without explicit cleanup methods, which could lead to test flakiness. Consider implementing@Before
and@After
methods to manage coroutine scopes consistently.🔗 Analysis chain
Consider adding test lifecycle management
While the
roomScope
correctly uses limited parallelism, there's no explicit cleanup of coroutines between tests. This could lead to test flakiness if coroutines from previous tests are still active.Consider adding a
@Before
setup and@After
cleanup:🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 1447