Skip to content
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
wants to merge 21 commits into
base: feature/roomlifecycle-attach-with-retry
Choose a base branch
from
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 Oct 25, 2024
0a6a45e
Merge branch 'feature/roomlifecycle-attach-with-retry' into tests/roo…
sacOO7 Oct 29, 2024
983ec92
Fixed RoomLifecycleManagerTest, added sequentialRoomScope property to…
sacOO7 Oct 29, 2024
18cc65d
Marked atomicCoroutineScope as internal to access from tests, added e…
sacOO7 Nov 5, 2024
30ad922
Refactored RoomLifecycleManagerTest, added more assertions for CHA-RL1d
sacOO7 Nov 5, 2024
0a9d391
Marked atomicCoroutineScope as private, accessed via reflection+exten…
sacOO7 Nov 5, 2024
52005c0
Bumped up io.mocck test dependency to latest version
sacOO7 Nov 6, 2024
b6f4dbd
Added channel attach room lifecycle spec CHA-RL1f, CHA-RL1g, updated
sacOO7 Nov 6, 2024
1d92116
Added mising unit test case blocks for channel attach
sacOO7 Nov 6, 2024
29a9782
Added test for spec CHA-RL1h1 channel attach, improved exception hand…
sacOO7 Nov 7, 2024
0f400b1
Merge branch 'feature/roomlifecycle-attach-with-retry' into tests/roo…
sacOO7 Nov 7, 2024
54a01c3
Refactored roomLifeCycle ATTACH tests with respective spec
sacOO7 Nov 7, 2024
2fee93d
Added channel attach retry test as per spec CHA-RL1h3
sacOO7 Nov 7, 2024
e6b46ff
Added channel attach unit test for contributor failure, get all remai…
sacOO7 Nov 7, 2024
f097e96
Added channel attach failure test, retry channel detach remaining cha…
sacOO7 Nov 7, 2024
e73b9ba
Annotated RoomLifeCycleManager code with right spec tags, refactored …
sacOO7 Nov 8, 2024
a9fffc2
Merge branch 'feature/roomlifecycle-attach-with-retry' into tests/roo…
sacOO7 Nov 8, 2024
774cc3b
Fixed linting issues for roomlifecycle attach tests
sacOO7 Nov 8, 2024
4fc33c7
Merge branch 'feature/roomlifecycle-attach-with-retry' into tests/roo…
sacOO7 Nov 11, 2024
097e82c
Added detach delay to fix test flakiness for channel detach
sacOO7 Nov 11, 2024
f4883bc
Refactored room attach tests with proper naming convention,
sacOO7 Nov 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"),
)
Comment on lines +32 to +34
Copy link

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:

private lateinit var roomScope: CoroutineScope

@Before
fun setup() {
    roomScope = CoroutineScope(
        Dispatchers.Default.limitedParallelism(1) + CoroutineName("roomId")
    )
}

@After
fun cleanup() {
    roomScope.cancel()
}
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for similar test lifecycle management patterns in other test files
rg -A 5 "roomScope.*=.*CoroutineScope" --type kotlin

Length of output: 1447


@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)
}
}
Loading