jbonofre opened a new pull request, #2975:
URL: https://github.com/apache/karaf/pull/2975

   `GraphQLExampleTest.testWebSocket` fails intermittently on CI, for example 
on #2974 ([macOS 
job](https://github.com/apache/karaf/actions/runs/37203406623/job/111441366798))
 and on a `karaf-4.4.x` push build that only bumped a dependency 
([run](https://github.com/apache/karaf/actions/runs/36812073168)):
   
   ```
   GraphQLExampleTest.testWebSocket:94 junit.framework.AssertionFailedError
   ```
   
   The test calls `client.connect(...)`, which is asynchronous, and adds a book 
right away. On the server, `GraphQLWebSocketExample` subscribes to the book 
feed only once the websocket is opened, on a `PublishSubject` created at that 
moment, so a book added before that is never published to the client. When the 
mutation is processed first, the client gets no message and the assertion fails 
after the 10 seconds of `awaitClose`.
   
   The retry fails the same way, because the websocket of the first attempt is 
still open: in the ubuntu run, the book added by the second attempt is received 
by the socket of the first one.
   
   This change:
   
   - waits for the websocket client to be connected
   - adds books until a message is received, for up to 30 seconds, instead of 
adding a single one and sleeping for 10 seconds
   - adds `SimpleSocket.awaitMessage(...)`, and keeps the received messages in 
a thread safe list, as they are added by a Jetty thread and read by the test
   - stops the client in a `finally` block, so a failed attempt does not leave 
its websocket open for the retry (this also removes the `NoClassDefFoundError` 
printed by the `JettyShutdownThread` after a failure)
   
   Only for `karaf-4.4.x`: on `main` this test is currently ignored.
   
   Tested locally on JDK 11:
   
   - with a `Thread.sleep(3000)` temporarily added before the subscription in 
`GraphQLWebSocketExample.onOpen`, the test fails like on CI without this 
change, and passes with it (the fourth book is the one received)
   - `mvn -o test -Ptest -Dtest=GraphQLExampleTest,WebSocketExampleTest` in 
`itests/test`, 3 times: 4 tests run, 0 failures
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to