Ensure we finish setup mock before we use it in Http2ConnectionRoundtripTest.headersWriteForPeerStreamWhichWasResetShouldNotGoAway (#9645)

Motivation:

We did dispatch the client code before we did finish setup the mock and so may end up with org.mockito.exceptions.misusing.UnfinishedStubbingException if the connect happens quickly enough.

See https://ci.netty.io/job/netty-centos6-java8-prb/1637/testReport/junit/io.netty.handler.codec.http2/Http2ConnectionRoundtripTest/headersWriteForPeerStreamWhichWasResetShouldNotGoAway/

Modifications:

First finish setup the mock and the dispatch.

Result:

Fix flacky test
This commit is contained in:
Norman Maurer 2019-10-09 09:10:38 +04:00
parent 3f6af1fc1d
commit 3a48010c42

View File

@ -453,14 +453,7 @@ public class Http2ConnectionRoundtripTest {
final CountDownLatch serverWriteHeadersLatch = new CountDownLatch(1); final CountDownLatch serverWriteHeadersLatch = new CountDownLatch(1);
final AtomicReference<Throwable> serverWriteHeadersCauseRef = new AtomicReference<>(); final AtomicReference<Throwable> serverWriteHeadersCauseRef = new AtomicReference<>();
final Http2Headers headers = dummyHeaders();
final int streamId = 3; final int streamId = 3;
runInChannel(clientChannel, () -> {
http2Client.encoder().writeHeaders(ctx(), streamId, headers, CONNECTION_STREAM_ID,
DEFAULT_PRIORITY_WEIGHT, false, 0, false, newPromise());
http2Client.encoder().writeRstStream(ctx(), streamId, Http2Error.CANCEL.code(), newPromise());
http2Client.flush(ctx());
});
doAnswer((Answer<Void>) invocationOnMock -> { doAnswer((Answer<Void>) invocationOnMock -> {
if (streamId == (Integer) invocationOnMock.getArgument(1)) { if (streamId == (Integer) invocationOnMock.getArgument(1)) {
@ -469,6 +462,14 @@ public class Http2ConnectionRoundtripTest {
return null; return null;
}).when(serverListener).onRstStreamRead(any(ChannelHandlerContext.class), eq(streamId), anyLong()); }).when(serverListener).onRstStreamRead(any(ChannelHandlerContext.class), eq(streamId), anyLong());
final Http2Headers headers = dummyHeaders();
runInChannel(clientChannel, () -> {
http2Client.encoder().writeHeaders(ctx(), streamId, headers, CONNECTION_STREAM_ID,
DEFAULT_PRIORITY_WEIGHT, false, 0, false, newPromise());
http2Client.encoder().writeRstStream(ctx(), streamId, Http2Error.CANCEL.code(), newPromise());
http2Client.flush(ctx());
});
assertTrue(serverSettingsAckLatch.await(DEFAULT_AWAIT_TIMEOUT_SECONDS, SECONDS)); assertTrue(serverSettingsAckLatch.await(DEFAULT_AWAIT_TIMEOUT_SECONDS, SECONDS));
assertTrue(serverGotRstLatch.await(DEFAULT_AWAIT_TIMEOUT_SECONDS, SECONDS)); assertTrue(serverGotRstLatch.await(DEFAULT_AWAIT_TIMEOUT_SECONDS, SECONDS));