Repository navigation
Make releasing a realtime channel that isn't detached an error (RTS4c-e) #1251
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
Open
SimonWoolf
wants to merge
1
commit into
integration/v2
Choose a base branch
from
release-throw-unless-detached
base: integration/v2
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 all commits
Commits
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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
129 changes: 129 additions & 0 deletions
129
lib/src/test/kotlin/io/ably/pubsub/uts/unit/realtime/ChannelsCollectionTest.kt
This file contains hidden or 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,129 @@ | ||
| package io.ably.pubsub.uts.unit.realtime | ||
|
|
||
| import io.ably.pubsub.uts.infra.unit.* | ||
| import io.ably.pubsub.realtime.ChannelState | ||
| import io.ably.pubsub.realtime.ConnectionState | ||
| import io.ably.pubsub.types.AblyException | ||
| import io.ably.pubsub.types.ProtocolMessage | ||
| import io.ably.pubsub.uts.infra.awaitChannelState | ||
| import io.ably.pubsub.uts.infra.awaitState | ||
| import kotlinx.coroutines.test.runTest | ||
| import java.util.UUID | ||
| import java.util.concurrent.CopyOnWriteArrayList | ||
| import kotlin.test.* | ||
|
|
||
| class ChannelsCollectionTest { | ||
|
|
||
| /** | ||
| * @UTS realtime/unit/RTS4c/release-nonexistent-noop-0 | ||
| */ | ||
| @Test | ||
| fun `RTS4c - release on non-existent channel is no-op`() { | ||
| val channelName = "test-RTS4c-nonexistent-${UUID.randomUUID()}" | ||
| val client = TestRealtimeClient { autoConnect = false } | ||
|
|
||
| client.channels.release(channelName) | ||
|
|
||
| assertFalse(client.channels.containsKey(channelName)) | ||
| client.close() | ||
| } | ||
|
|
||
| /** | ||
| * @UTS realtime/unit/RTS4d/release-removes-channel-0 | ||
| */ | ||
| @Test | ||
| fun `RTS4d - release removes an initialized channel`() { | ||
| val channelName = "test-RTS4d-${UUID.randomUUID()}" | ||
| val client = TestRealtimeClient { autoConnect = false } | ||
|
|
||
| val channel = client.channels.get(channelName) | ||
| assertEquals(ChannelState.initialized, channel.state) | ||
| assertTrue(client.channels.containsKey(channelName)) | ||
|
|
||
| client.channels.release(channelName) | ||
|
|
||
| assertFalse(client.channels.containsKey(channelName)) | ||
| client.close() | ||
| } | ||
|
|
||
| /** | ||
| * @UTS realtime/unit/RTS4d/release-after-detach-1 | ||
| */ | ||
| @Test | ||
| fun `RTS4d - release removes a channel once detached`() = runTest { | ||
| val channelName = "test-RTS4d-detached-${UUID.randomUUID()}" | ||
| lateinit var mockWs: MockWebSocket | ||
| mockWs = MockWebSocket { | ||
| onConnectionAttempt = { conn -> conn.respondWithSuccess(CONNECTED_MESSAGE) } | ||
| onMessageFromClient = { msg -> | ||
| when (msg.action) { | ||
| ProtocolMessage.Action.attach -> | ||
| mockWs.sendToClient(ProtocolMessage(ProtocolMessage.Action.attached, msg.channel)) | ||
| ProtocolMessage.Action.detach -> | ||
| mockWs.sendToClient(ProtocolMessage(ProtocolMessage.Action.detached, msg.channel)) | ||
| else -> Unit | ||
| } | ||
| } | ||
| } | ||
| val client = TestRealtimeClient { | ||
| autoConnect = false | ||
| install(mockWs) | ||
| } | ||
| val channel = client.channels.get(channelName) | ||
|
|
||
| client.connect() | ||
| awaitState(client, ConnectionState.connected) | ||
|
|
||
| channel.attach() | ||
| awaitChannelState(channel, ChannelState.attached) | ||
| channel.detach() | ||
| awaitChannelState(channel, ChannelState.detached) | ||
|
|
||
| client.channels.release(channelName) | ||
|
|
||
| assertFalse(client.channels.containsKey(channelName)) | ||
| client.close() | ||
| } | ||
|
|
||
| /** | ||
| * @UTS realtime/unit/RTS4e/release-attached-fails-0 | ||
| */ | ||
| @Test | ||
| fun `RTS4e - release of an attached channel fails`() = runTest { | ||
| val channelName = "test-RTS4e-attached-${UUID.randomUUID()}" | ||
| val capturedDetachMessages = CopyOnWriteArrayList<ProtocolMessage>() | ||
| lateinit var mockWs: MockWebSocket | ||
| mockWs = MockWebSocket { | ||
| onConnectionAttempt = { conn -> conn.respondWithSuccess(CONNECTED_MESSAGE) } | ||
| onMessageFromClient = { msg -> | ||
| when (msg.action) { | ||
| ProtocolMessage.Action.attach -> | ||
| mockWs.sendToClient(ProtocolMessage(ProtocolMessage.Action.attached, msg.channel)) | ||
| ProtocolMessage.Action.detach -> capturedDetachMessages.add(msg) | ||
| else -> Unit | ||
| } | ||
| } | ||
| } | ||
| val client = TestRealtimeClient { | ||
| autoConnect = false | ||
| install(mockWs) | ||
| } | ||
| val channel = client.channels.get(channelName) | ||
|
|
||
| client.connect() | ||
| awaitState(client, ConnectionState.connected) | ||
|
|
||
| channel.attach() | ||
| awaitChannelState(channel, ChannelState.attached) | ||
|
|
||
| val error = assertFailsWith<AblyException> { client.channels.release(channelName) }.errorInfo | ||
|
|
||
| assertEquals(90011, error.code) | ||
| assertEquals(400, error.statusCode) | ||
| assertEquals(ChannelState.attached, channel.state) | ||
| assertTrue(client.channels.containsKey(channelName)) | ||
| assertSame(channel, client.channels.get(channelName)) | ||
| assertEquals(0, capturedDetachMessages.size) | ||
| client.close() | ||
| } | ||
| } |
This file contains hidden or 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
This file contains hidden or 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
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.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
Document and declare the new
AblyExceptionon the adapterreleasecontract.PubSubRealtimeClient.Channels.releasenow declaresthrows AblyException(code 90011) for any realtime channel that is notINITIALIZED,DETACHED, orFAILED. The adapter KDoc states the state restriction. It does not state thatreleasethrows when the restriction is violated. It also does not tell callers to detach and wait first.Kotlin does not have checked exceptions, so Kotlin callers of the adapter get no compiler signal about this failure path. A Java caller of this interface cannot write
catch (AblyException e)aroundrelease(name)without@Throws. javac rejects a catch of a checked exception that the callee does not declare.Add
@Throws(AblyException::class)and a@throwsKDoc entry that matches the Java interface.📝 Proposed fix
Import
io.ably.pubsub.types.AblyExceptionif the file does not import it yet.🤖 Prompt for AI Agents