cdap
cdap copied to clipboard
Make sure that response is processed completely before stopping service in the AppWithCustomTx test case.
If service is stopped before the current inflight requests are processed completely, we see failure in the expected value in the test case. Added synchronization mechanism between service and test case to make sure we wait for the current inflight response to be completely processed before stopping the service program.
This failure becomes more pronounced after this change - https://github.com/cdapio/cdap/pull/13096/files#diff-07c7839ccb633f3535e6e5fcb30afaca412536ed747d21e30c60ffb447ce5c08R2118
PUT call here returns the 200 and HttpContentProducer - https://github.com/cdapio/cdap/blob/develop/cdap-unit-test/src/test/java/io/cdap/cdap/test/app/AppWithCustomTx.java#L408.
Test case checks for 200 return code and return from here - https://github.com/cdapio/cdap/blob/develop/cdap-unit-test/src/test/java/io/cdap/cdap/test/app/TestFrameworkTestRun.java#L2113 at which point connection is closed.
It looks like the onFinish
and onError
callback methods of the HttpBodyProducer are called asynchronously when the response content is streamed and marked as done from the listener attached here - https://github.com/cdapio/netty-http/blob/develop/src/main/java/io/cdap/http/internal/BasicHttpResponder.java#L191.
Since these listeners are invoked after the content is sent, it is possible that the thread executing test case finish first causing these methods to not to complete.
ah I see, thanks for explanation.