Fixes #836 - Test Failure: HttpClientTransportOverHTTP2Test.testLastStreamId()

Fixed race condition: the completion was happening before the stream
promise for the request was succeeded.
This commit is contained in:
Simone Bordet 2016-08-12 17:09:57 +02:00
parent 9f9e9ecaf9
commit ea20a5f2ef
2 changed files with 27 additions and 4 deletions

View File

@ -25,7 +25,6 @@ import org.eclipse.jetty.client.HttpReceiver;
import org.eclipse.jetty.client.HttpSender; import org.eclipse.jetty.client.HttpSender;
import org.eclipse.jetty.client.api.Result; import org.eclipse.jetty.client.api.Result;
import org.eclipse.jetty.http2.ErrorCode; import org.eclipse.jetty.http2.ErrorCode;
import org.eclipse.jetty.http2.HTTP2Stream;
import org.eclipse.jetty.http2.api.Session; import org.eclipse.jetty.http2.api.Session;
import org.eclipse.jetty.http2.api.Stream; import org.eclipse.jetty.http2.api.Stream;
import org.eclipse.jetty.http2.frames.ResetFrame; import org.eclipse.jetty.http2.frames.ResetFrame;
@ -78,7 +77,6 @@ public class HttpChannelOverHTTP2 extends HttpChannel
public void setStream(Stream stream) public void setStream(Stream stream)
{ {
this.stream = stream; this.stream = stream;
getHttpExchange().getRequest().attribute(HTTP2Stream.class.getName(), stream);
} }
@Override @Override

View File

@ -34,6 +34,7 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -50,7 +51,6 @@ import org.eclipse.jetty.http.HttpVersion;
import org.eclipse.jetty.http.MetaData; import org.eclipse.jetty.http.MetaData;
import org.eclipse.jetty.http2.ErrorCode; import org.eclipse.jetty.http2.ErrorCode;
import org.eclipse.jetty.http2.HTTP2Session; import org.eclipse.jetty.http2.HTTP2Session;
import org.eclipse.jetty.http2.HTTP2Stream;
import org.eclipse.jetty.http2.api.Session; import org.eclipse.jetty.http2.api.Session;
import org.eclipse.jetty.http2.api.Stream; import org.eclipse.jetty.http2.api.Stream;
import org.eclipse.jetty.http2.api.server.ServerSessionListener; import org.eclipse.jetty.http2.api.server.ServerSessionListener;
@ -237,8 +237,32 @@ public class HttpClientTransportOverHTTP2Test extends AbstractTest
CountDownLatch latch = new CountDownLatch(2); CountDownLatch latch = new CountDownLatch(2);
AtomicInteger lastStream = new AtomicInteger(); AtomicInteger lastStream = new AtomicInteger();
AtomicReference<Stream> streamRef = new AtomicReference<>();
CountDownLatch streamLatch = new CountDownLatch(1);
client = new HttpClient(new HttpClientTransportOverHTTP2(new HTTP2Client()) client = new HttpClient(new HttpClientTransportOverHTTP2(new HTTP2Client())
{ {
@Override
protected HttpConnectionOverHTTP2 newHttpConnection(HttpDestination destination, Session session)
{
return new HttpConnectionOverHTTP2(destination, session)
{
@Override
protected HttpChannelOverHTTP2 newHttpChannel()
{
return new HttpChannelOverHTTP2(getHttpDestination(), this, getSession())
{
@Override
public void setStream(Stream stream)
{
super.setStream(stream);
streamRef.set(stream);
streamLatch.countDown();
}
};
}
};
}
@Override @Override
protected void onClose(HttpConnectionOverHTTP2 connection, GoAwayFrame frame) protected void onClose(HttpConnectionOverHTTP2 connection, GoAwayFrame frame)
{ {
@ -268,9 +292,10 @@ public class HttpClientTransportOverHTTP2Test extends AbstractTest
latch.countDown(); latch.countDown();
}); });
Assert.assertTrue(streamLatch.await(5, TimeUnit.SECONDS));
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS)); Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
Stream stream = (Stream)request.getAttributes().get(HTTP2Stream.class.getName()); Stream stream = streamRef.get();
Assert.assertNotNull(stream); Assert.assertNotNull(stream);
Assert.assertEquals(lastStream.get(), stream.getId()); Assert.assertEquals(lastStream.get(), stream.getId());
} }