You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Prevent starting second subscription with the same id, remove he complete message as it's not needed, and probably preventing flux from closing. (ExpediaGroup#520)
Copy file name to clipboardExpand all lines: graphql-kotlin-spring-server/src/main/kotlin/com/expediagroup/graphql/spring/execution/ApolloSubscriptionProtocolHandler.kt
+6-5Lines changed: 6 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -65,10 +65,7 @@ class ApolloSubscriptionProtocolHandler(
Copy file name to clipboardExpand all lines: graphql-kotlin-spring-server/src/main/kotlin/com/expediagroup/graphql/spring/execution/ApolloSubscriptionSessionState.kt
Copy file name to clipboardExpand all lines: graphql-kotlin-spring-server/src/test/kotlin/com/expediagroup/graphql/spring/execution/ApolloSubscriptionProtocolHandlerTest.kt
+57-4Lines changed: 57 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -244,11 +244,11 @@ class ApolloSubscriptionProtocolHandlerTest {
244
244
fun`Return GQL_CONNECTION_ERROR when sending GQL_START but id is null`() {
245
245
val config:GraphQLConfigurationProperties= mockk()
246
246
val operationMessage =SubscriptionOperationMessage(type =GQL_START.type, id =null).toJson()
247
-
valsession:WebSocketSession= mockk()
247
+
valmockSession:WebSocketSession= mockk { every { id } returns "123" }
248
248
val subscriptionHandler:SubscriptionHandler= mockk()
249
249
250
250
val handler =ApolloSubscriptionProtocolHandler(config, subscriptionHandler, objectMapper)
251
-
val flux = handler.handle(operationMessage, session)
251
+
val flux = handler.handle(operationMessage, mockSession)
252
252
253
253
val message = flux.blockFirst(Duration.ofSeconds(2))
254
254
assertNotNull(message)
@@ -316,7 +316,60 @@ class ApolloSubscriptionProtocolHandlerTest {
316
316
val graphQLResponse:GraphQLResponse= objectMapper.convertValue(payload)
317
317
assertEquals(expected ="myData", actual = graphQLResponse.data)
318
318
319
-
assertEquals(expected =2, actual = flux.count().block())
319
+
assertEquals(expected =1, actual = flux.count().block())
320
+
verify(exactly =0) { session.close() }
321
+
}
322
+
323
+
@Test
324
+
fun`Return GQL_COMPLETE when sending GQL_STOP with GraphQLRequest having operation id of running operation`() {
325
+
val config:GraphQLConfigurationProperties= mockk()
326
+
val graphQLRequest =GraphQLRequest("{ message }")
327
+
val startRequest =SubscriptionOperationMessage(type =GQL_START.type, id ="abc", payload = graphQLRequest).toJson()
328
+
val stopRequest =SubscriptionOperationMessage(type =GQL_STOP.type, id ="abc").toJson()
329
+
val session:WebSocketSession= mockk {
330
+
every { close() } returns mockk()
331
+
every { id } returns "123"
332
+
}
333
+
val subscriptionHandler:SubscriptionHandler= mockk {
334
+
every { executeSubscription(eq(graphQLRequest)) } returns Flux.just(GraphQLResponse("myData"))
335
+
}
336
+
337
+
val handler =ApolloSubscriptionProtocolHandler(config, subscriptionHandler, objectMapper)
338
+
val startFlux = handler.handle(startRequest, session)
339
+
startFlux.blockFirst(Duration.ofSeconds(2))
340
+
val stopFlux = handler.handle(stopRequest, session)
341
+
342
+
StepVerifier.create(stopFlux)
343
+
.expectSubscription()
344
+
.expectNextMatches { it.type =="complete" }
345
+
.thenCancel()
346
+
.verify()
347
+
348
+
assertEquals(expected =1, actual = startFlux.count().block())
349
+
assertEquals(expected =1, actual = stopFlux.count().block())
350
+
verify(exactly =0) { session.close() }
351
+
}
352
+
353
+
@Test
354
+
fun`Dont start second subscription when operation id is already in activeOperations`() {
355
+
val config:GraphQLConfigurationProperties= mockk()
356
+
val graphQLRequest =GraphQLRequest("{ message }")
357
+
val operationMessage =SubscriptionOperationMessage(type =SubscriptionOperationMessage.ClientMessages.GQL_START.type, id ="abc", payload = graphQLRequest).toJson()
358
+
val session:WebSocketSession= mockk {
359
+
every { close() } returns mockk()
360
+
every { id } returns "123"
361
+
}
362
+
val subscriptionHandler:SubscriptionHandler= mockk {
363
+
every { executeSubscription(eq(graphQLRequest)) } returns Flux.just(GraphQLResponse("myData"))
364
+
}
365
+
366
+
val handler =ApolloSubscriptionProtocolHandler(config, subscriptionHandler, objectMapper)
367
+
val flux = handler.handle(operationMessage, session)
368
+
flux.blockFirst(Duration.ofSeconds(2))
369
+
val fluxTwo = handler.handle(operationMessage, session)
370
+
371
+
assertEquals(expected =1, actual = flux.count().block())
372
+
assertEquals(expected =0, actual = fluxTwo.count().block())
320
373
verify(exactly =0) { session.close() }
321
374
}
322
375
@@ -337,7 +390,7 @@ class ApolloSubscriptionProtocolHandlerTest {
337
390
val handler =ApolloSubscriptionProtocolHandler(config, subscriptionHandler, objectMapper)
338
391
val flux = handler.handle(operationMessage, session)
339
392
340
-
assertEquals(expected =2, actual = flux.count().block())
393
+
assertEquals(expected =1, actual = flux.count().block())
341
394
val message = flux.blockFirst(Duration.ofSeconds(2))
342
395
assertNotNull(message)
343
396
assertEquals(expected =GQL_ERROR.type, actual = message.type)
0 commit comments