@@ -138,6 +138,9 @@ final class APIKeyTests: IntegrationTestBase {
138138 }
139139
140140 func testMaxSubscriptionReached( ) async throws {
141+ let subscriptionLimit = 200
142+ let failedSubscriptionCount = 5
143+
141144 let configuration = try AWSAppSyncConfiguration ( with: . amplifyOutputs)
142145 let store = ApolloStore ( cache: InMemoryNormalizedCache ( ) )
143146 let authorizer = APIKeyAuthorizer ( apiKey: configuration. apiKey ?? " " )
@@ -148,13 +151,12 @@ final class APIKeyTests: IntegrationTestBase {
148151 let websocket = AppSyncWebSocketClient ( endpointURL: configuration. endpoint,
149152 authorizer: authorizer)
150153 let receivedConnection = expectation ( description: " received connection " )
151- receivedConnection. expectedFulfillmentCount = 200
154+ receivedConnection. expectedFulfillmentCount = subscriptionLimit
152155
153156 let receivedMaxSubscriptionsReachedError = expectation ( description: " received MaxSubscriptionsReachedError " )
154- receivedMaxSubscriptionsReachedError. expectedFulfillmentCount = 5
157+ receivedMaxSubscriptionsReachedError. expectedFulfillmentCount = failedSubscriptionCount
155158
156159 let sink = websocket. publisher. sink { event in
157- print ( " Received event: \( event) " )
158160 if case . string( let message) = event {
159161 if message. contains ( " start_ack " ) {
160162 receivedConnection. fulfill ( )
@@ -171,16 +173,18 @@ final class APIKeyTests: IntegrationTestBase {
171173 webSocketNetworkTransport: webSocketTransport
172174 )
173175 let client = ApolloClient ( networkTransport: splitTransport, store: store)
174-
176+
177+ try await Task . sleep ( nanoseconds: 5 * 1_000_000_000 ) // 5 seconds
178+
175179 var cancellables = [ Cancellable] ( )
176- for _ in 1 ... 205 {
180+ for _ in 1 ... subscriptionLimit + failedSubscriptionCount {
177181 cancellables. append ( client. subscribe ( subscription: OnCreateSubscription ( ) ) { _ in } )
178182 }
179-
180- await fulfillment ( of: [ receivedConnection, receivedMaxSubscriptionsReachedError] , timeout: 30 )
183+
184+ await fulfillment ( of: [ receivedConnection, receivedMaxSubscriptionsReachedError] , timeout: 10 )
185+
181186 for cancellable in cancellables {
182187 cancellable. cancel ( )
183188 }
184189 }
185-
186190}
0 commit comments