Skip to content

Commit a2ee278

Browse files
authored
Merge branch 'main' into mattcreaser/publishing-convention
2 parents ebda5ac + d9eb7a9 commit a2ee278

File tree

6 files changed

+34
-5
lines changed

6 files changed

+34
-5
lines changed

appsync/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## [Release 1.0.1](https://github.com/aws-amplify/amplify-android/releases/tag/release_events_v1.0.1)
2+
3+
### Bug Fixes
4+
- **events:** Ensure WebSocket connection error notifies client ([#3127](https://github.com/aws-amplify/amplify-android/issues/3127))
5+
6+
[See all changes between 1.0.0 and 1.1.0](https://github.com/aws-amplify/amplify-android/compare/release_events_v1.0.0...release_events_v1.0.1)
7+
18
# Release 1.0.0
29

310
Initial Release

appsync/aws-sdk-appsync-events/src/androidTest/java/com/amazonaws/sdk/appsync/events/EventsWebSocketClientTests.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import androidx.test.platform.app.InstrumentationRegistry
1818
import app.cash.turbine.test
1919
import app.cash.turbine.turbineScope
2020
import com.amazonaws.sdk.appsync.core.authorizers.ApiKeyAuthorizer
21+
import com.amazonaws.sdk.appsync.events.data.ConnectException
2122
import com.amazonaws.sdk.appsync.events.data.InvalidInputException
2223
import com.amazonaws.sdk.appsync.events.data.PublishResult
2324
import com.amazonaws.sdk.appsync.events.data.UnauthorizedException
@@ -47,6 +48,7 @@ import org.junit.Test
4748
internal class EventsWebSocketClientTests {
4849
private val eventsConfig = getEventsConfig(InstrumentationRegistry.getInstrumentation().targetContext)
4950
private val apiKeyAuthorizer = ApiKeyAuthorizer(eventsConfig.apiKey)
51+
private val badApiKeyAuthorizer = ApiKeyAuthorizer("bad-api-key")
5052
private val webSocketLogCapture = EventsLibraryLogCapture()
5153
private val defaultChannel = "default/${UUID.randomUUID()}"
5254
private val customChannel = "custom/${UUID.randomUUID()}"
@@ -60,6 +62,12 @@ internal class EventsWebSocketClientTests {
6062
loggerProvider = { _ -> webSocketLogCapture }
6163
)
6264
)
65+
66+
private val badWebSocketClient = events.createWebSocketClient(
67+
badApiKeyAuthorizer,
68+
badApiKeyAuthorizer,
69+
badApiKeyAuthorizer
70+
)
6371
private val backgroundScope = CoroutineScope(Dispatchers.IO)
6472

6573
@After
@@ -109,6 +117,15 @@ internal class EventsWebSocketClientTests {
109117
)
110118
}
111119

120+
@Test
121+
fun testConnectionFailure() = runBlockingWithTimeout {
122+
turbineScope(timeout = 10.seconds) {
123+
badWebSocketClient.subscribe(defaultChannel).test(timeout = 10.seconds) {
124+
awaitError() shouldBe ConnectException(UnauthorizedException())
125+
}
126+
}
127+
}
128+
112129
@Test
113130
fun testPublishWithBadAuth(): Unit = runBlockingWithTimeout {
114131
// Publish the message

appsync/aws-sdk-appsync-events/src/main/java/com/amazonaws/sdk/appsync/events/data/WebSocketMessage.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,10 @@ internal sealed class WebSocketMessage {
9797

9898
@Serializable
9999
@SerialName("connection_error")
100-
internal data class ConnectionError(val errors: List<EventsError>) : Received()
100+
internal data class ConnectionError(
101+
override val id: String? = null,
102+
override val errors: List<EventsError>
103+
) : Received(), ErrorContainer
101104

102105
@Serializable
103106
internal sealed class Subscription : Received() {
@@ -189,7 +192,8 @@ internal sealed class WebSocketMessage {
189192

190193
internal data class Closed(val reason: WebSocketDisconnectReason) : WebSocketMessage()
191194

192-
// All errors contain an id and errors list
195+
// All errors contain an errors list
196+
// Most events contain an id, which is either a channel id or a publish id
193197
internal interface ErrorContainer {
194198
val id: String?
195199
val errors: List<EventsError>

appsync/aws-sdk-appsync-events/src/test/java/com/amazonaws/sdk/appsync/events/EventsWebSocketTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import com.amazonaws.sdk.appsync.events.mocks.TestAuthorizer
2222
import com.amazonaws.sdk.appsync.events.utils.JsonUtils
2323
import io.kotest.assertions.throwables.shouldThrow
2424
import io.kotest.matchers.shouldBe
25+
import io.kotest.matchers.string.shouldStartWith
2526
import io.mockk.every
2627
import io.mockk.mockk
2728
import io.mockk.slot
@@ -92,7 +93,7 @@ internal class EventsWebSocketTest {
9293
capturedRequest.headers.size shouldBe 4
9394
capturedRequest.headers["Sec-WebSocket-Protocol"] shouldBe "aws-appsync-event-ws"
9495
capturedRequest.headers["host"] shouldBe "11111111111111111111111111.appsync-api.us-east-1.amazonaws.com"
95-
capturedRequest.headers["x-amz-user-agent"] shouldBe "aws-appsync-events-android#1.0.0"
96+
capturedRequest.headers["x-amz-user-agent"] shouldStartWith "aws-appsync-events-android#1."
9697
capturedRequest.headers["testKey"] shouldBe "default"
9798
capturedRequest.body shouldBe null
9899
}

appsync/aws-sdk-appsync-events/src/test/java/com/amazonaws/sdk/appsync/events/data/WebSocketMessageTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class WebSocketMessageTest {
112112

113113
val deserialized = json.decodeFromString<WebSocketMessage.Received>(jsonString)
114114
deserialized shouldBe WebSocketMessage.Received.ConnectionError(
115-
listOf(
115+
errors = listOf(
116116
EventsError("UnauthorizedException", "Test error message")
117117
)
118118
)

appsync/version.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION_NAME=1.0.0
1+
VERSION_NAME=1.0.1

0 commit comments

Comments
 (0)