graphql-spring-boot icon indicating copy to clipboard operation
graphql-spring-boot copied to clipboard

GraphQLTestSubscription fails to init() when using @GraphQLTest

Open lassemaatta opened this issue 3 years ago • 2 comments

Describe the bug

GraphQLTestSubscription fails to create a WebSocket connection in a test.

To Reproduce Steps to reproduce the behavior:

  1. Define a test class annotated with @GraphQLTest
  2. Autowire the GraphQLTestSubscription dependency
  3. call init() on the test subcription
  4. See error:
Caused by: javax.websocket.DeploymentException: The HTTP response from the server [404] did not permit the HTTP upgrade to WebSocket
	at org.apache.tomcat.websocket.WsWebSocketContainer.connectToServerRecursive(WsWebSocketContainer.java:440)
	at org.apache.tomcat.websocket.WsWebSocketContainer.connectToServer(WsWebSocketContainer.java:197)
	at com.graphql.spring.boot.test.GraphQLTestSubscription.initClient(GraphQLTestSubscription.java:387)

Expected behavior GraphQLTestSubscription should establish the WebSocket connection without errors.

Additional context I did notice that @GraphQLTest does not seem to include GraphQLWebsocketAutoConfiguration. However, importing it to the test context did not seem to fix the issue.

lassemaatta avatar Mar 15 '21 10:03 lassemaatta

Until this is fixed, you can use @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) instead of @GraphQLTest

BlasiusSecundus avatar Mar 20 '21 10:03 BlasiusSecundus

I could reproduce the issue with integration test. It seems that some necesary beans are missing when using @GraphQLTest, even if GraphQLWebsocketAutoConfiguration is added.

Number of beans

  • when using @GraphQLTest - 100 ❌
  • when using @GraphQLTest with GraphQLWebsocketAutoConfiguration added - 106 ❌
  • when using @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) - 277 ✔️

BlasiusSecundus avatar Mar 23 '21 20:03 BlasiusSecundus