New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Revise HttpMetricsHandlerTests and fix testServerConnectionsRecorder #2391
Revise HttpMetricsHandlerTests and fix testServerConnectionsRecorder #2391
Conversation
mmm, I forgot to push one polishing commit, please wait a moment before reviewing ... |
now, it is ok. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep formatting changes (when needed) in a separate change, it will be easier for the one that is reviewing the change.
reactor-netty-http/src/test/java/reactor/netty/http/HttpMetricsHandlerTests.java
Outdated
Show resolved
Hide resolved
reactor-netty-http/src/test/java/reactor/netty/http/HttpMetricsHandlerTests.java
Outdated
Show resolved
Hide resolved
reactor-netty-http/src/test/java/reactor/netty/http/HttpMetricsHandlerTests.java
Outdated
Show resolved
Hide resolved
reactor-netty-http/src/test/java/reactor/netty/http/HttpMetricsHandlerTests.java
Show resolved
Hide resolved
reactor-netty-http/src/test/java/reactor/netty/http/HttpMetricsHandlerTests.java
Outdated
Show resolved
Hide resolved
reactor-netty-http/src/test/java/reactor/netty/http/HttpMetricsHandlerTests.java
Outdated
Show resolved
Hide resolved
reactor-netty-http/src/test/java/reactor/netty/http/HttpMetricsHandlerTests.java
Outdated
Show resolved
Hide resolved
reactor-netty-http/src/test/java/reactor/netty/http/HttpMetricsHandlerTests.java
Outdated
Show resolved
Hide resolved
reactor-netty-http/src/test/java/reactor/netty/http/HttpMetricsHandlerTests.java
Outdated
Show resolved
Hide resolved
reactor-netty-http/src/test/java/reactor/netty/http/HttpMetricsHandlerTests.java
Outdated
Show resolved
Hide resolved
thanks Violeta, I have applied your suggestions, please re-take a look ? |
by the way, the error for macos-11/nio is unrelated to the changes. |
mmm, please wait, I need to check the windows error ... |
ok, the windows error is also unrelated to the changes. |
@violetagg , thank you for your review. |
This PR is a revamp of the HttpMetricsHandlerTests and also fixes a concurrency issue in testServerConnectionsRecorder, which sometimes fails with this exception:
Such exception can happen if the checkServerConnectionsRecorder method throws some exceptions.
So, the PR first catches any exceptions thrown from checkServerConnectionsRecorder, and then the testServerConnectionsRecorder asserts if the exception has not been thrown.
So, when doing this, we can then see the root cause exception (this exception comes from netty5 branch, bit it's the same issue in 1.0.x branch):
So, what is failing is this check from checkServerConnectionsRecorder method:
when checkServerConnectionsRecorder() is called, the number of connections on the server is surprisingly 0 instead of 1 ! it's a concurrency issue which may happen if CI is slow. Here is the reproducer scenario I can imagine for the moment:
we are testing an HTTP2 test, and the test succeeds, so when tearDown is called, the client connection provider is disposed. But because the system is slow, the server does not immediately see the close, it will see it eventually, but not immediately.
so, the next test is now executing, and then the ServerRecorder.recordServerConnectionOpened() is called: onServerConnectionsAmount is set to 1, but right after, recordServerConnectionClosed is called because the previous server test is still closing -> in this case, onServerConnectionsAmount is decremented and is wrongly set to 0
The PR is an attempt to fix this issue: it first dispose the client connection provider, then it waits for the recordServerConnectionClosed to be called, then it asserts the test expectations.
The PR is also a big refactoring, where all observeDisconnect usage has been removed.
The tests are now based on the following handlers:
Lastly, pay attention to the usage of HttpClient.doAfterResponseSuccess in various tests: this method call is important: it ensures that the AbstractHttpClientMetricsHandler.channelRead method has received the LastHttpContent response, and the recordRead has then been called, so metrics are up-to-date.
Fixes #2368