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

   This is the `main` version of #2975.
   
   ### testServlet
   
   `GraphQLExampleTest.testServlet` sends its first request right after the 
installation of the feature, while the HTTP service starts and registers the 
servlets asynchronously. It failed that way on CI ([Windows 
job](https://github.com/apache/karaf/actions/runs/37197308866/job/111432861507)):
 `Connection refused` on the first attempt, then a 404 on the retry.
   
   ```
   GraphQLExampleTest.testServlet:54->sendGetRequest:110 ยป FileNotFound 
http://localhost:9080/graphql?query=%7B+books+%7B+name+id+%7D+%7D
   ```
   
   This change adds an `awaitServlet(...)` helper that polls a servlet with 
Awaitility (up to 30 seconds) until the request is accepted and is not answered 
with a 404, and `testServlet` uses it for `/graphql` before sending its 
requests.
   
   ### testWebSocket
   
   This test is ignored on `main`, and stays ignored: the websocket upgrade 
still returns a 404. It also has a race of its own, which makes it flaky on 
`karaf-4.4.x` (see #2975): the server subscribes to the book feed only once the 
websocket is opened, so a book added before that is never published to the 
client.
   
   So that the test is correct when it is enabled again, it now:
   
   - waits for `/graphql` like `testServlet`
   - adds books until a message is received, for up to 30 seconds, instead of 
adding a single one and sleeping for 3 seconds
   - stops the client in a `finally` block
   
   `SimpleSocket` gets an `awaitMessage(...)` method for that, and keeps the 
received messages in a thread safe list, as they are added by a Jetty thread 
and read by the test.
   
   Unlike #2975, the test does not wait for `/graphql-websocket`: a plain 
request on it returns a 404 today, and I could not check what it returns once 
the endpoint works.
   
   ### Tests
   
   Locally on JDK 17:
   
   - I did not reproduce the `testServlet` failure as is: the servlet was 
registered when the installation returned. With a temporary test installing the 
feature in a background thread, a request sent without waiting fails with 
`Connection refused`, the servlet goes from connection refused to 404 to 
available, and the request sent after `awaitServlet` succeeds
   - `mvn -o test -Ptest -Dtest=GraphQLExampleTest,WebSocketExampleTest` in 
`itests/test`, 3 times: 4 tests run, 0 failures, 2 skipped (the two ignored 
websocket tests)
   - the `testWebSocket` changes are not covered: with `@Ignore` temporarily 
removed, the test fails at the upgrade (`Unexpected HTTP Response Status Code: 
404 Not Found`), before reaching the new code
   


-- 
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