public void GoAwaySentShouldCloseStreamsGreaterThanLastStream() { IHttp2Stream stream1 = server.Remote.CreateStream(3, false); IHttp2Stream stream2 = server.Remote.CreateStream(5, false); IHttp2Stream localStream = server.Local.CreateStream(4, false); server.GoAwaySent(3, (Http2Error)8, null); Assert.Equal(Http2StreamState.Open, stream1.State); Assert.Equal(Http2StreamState.Closed, stream2.State); Assert.Equal(3, server.Remote.LastStreamKnownByPeer()); Assert.Equal(5, server.Remote.LastStreamCreated); // The local endpoint must not be affected by a sent GOAWAY frame. Assert.Equal(-1, server.Local.LastStreamKnownByPeer()); Assert.Equal(Http2StreamState.Open, localStream.State); }
public void ListenerThrowShouldNotPreventOtherListenersFromBeingNotified() { var calledArray = new bool[128]; // The following setup will ensure that clientListener throws exceptions, and marks a value in an array // such that clientListener2 will verify that is is set or fail the test. int methodIndex = 0; _clientListener .Setup(x => x.OnStreamAdded(It.IsAny <IHttp2Stream>())) .Callback <IHttp2Stream>(s => ListenerExceptionThrower(calledArray, methodIndex)); _clientListener2 .Setup(x => x.OnStreamAdded(It.IsAny <IHttp2Stream>())) .Callback <IHttp2Stream>(s => ListenerVerifyCallAnswer(calledArray, methodIndex++)); _clientListener .Setup(x => x.OnStreamActive(It.IsAny <IHttp2Stream>())) .Callback <IHttp2Stream>(s => ListenerExceptionThrower(calledArray, methodIndex)); _clientListener2 .Setup(x => x.OnStreamActive(It.IsAny <IHttp2Stream>())) .Callback <IHttp2Stream>(s => ListenerVerifyCallAnswer(calledArray, methodIndex++)); _clientListener .Setup(x => x.OnStreamHalfClosed(It.IsAny <IHttp2Stream>())) .Callback <IHttp2Stream>(s => ListenerExceptionThrower(calledArray, methodIndex)); _clientListener2 .Setup(x => x.OnStreamHalfClosed(It.IsAny <IHttp2Stream>())) .Callback <IHttp2Stream>(s => ListenerVerifyCallAnswer(calledArray, methodIndex++)); _clientListener .Setup(x => x.OnStreamClosed(It.IsAny <IHttp2Stream>())) .Callback <IHttp2Stream>(s => ListenerExceptionThrower(calledArray, methodIndex)); _clientListener2 .Setup(x => x.OnStreamClosed(It.IsAny <IHttp2Stream>())) .Callback <IHttp2Stream>(s => ListenerVerifyCallAnswer(calledArray, methodIndex++)); _clientListener .Setup(x => x.OnStreamRemoved(It.IsAny <IHttp2Stream>())) .Callback <IHttp2Stream>(s => ListenerExceptionThrower(calledArray, methodIndex)); _clientListener2 .Setup(x => x.OnStreamRemoved(It.IsAny <IHttp2Stream>())) .Callback <IHttp2Stream>(s => ListenerVerifyCallAnswer(calledArray, methodIndex++)); _clientListener .Setup(x => x.OnGoAwaySent(It.IsAny <int>(), It.IsAny <Http2Error>(), It.IsAny <IByteBuffer>())) .Callback <int, Http2Error, IByteBuffer>((id, err, buf) => ListenerExceptionThrower(calledArray, methodIndex)); _clientListener2 .Setup(x => x.OnGoAwaySent(It.IsAny <int>(), It.IsAny <Http2Error>(), It.IsAny <IByteBuffer>())) .Callback <int, Http2Error, IByteBuffer>((id, err, buf) => ListenerVerifyCallAnswer(calledArray, methodIndex++)); _clientListener .Setup(x => x.OnGoAwayReceived(It.IsAny <int>(), It.IsAny <Http2Error>(), It.IsAny <IByteBuffer>())) .Callback <int, Http2Error, IByteBuffer>((id, err, buf) => ListenerExceptionThrower(calledArray, methodIndex)); _clientListener2 .Setup(x => x.OnGoAwayReceived(It.IsAny <int>(), It.IsAny <Http2Error>(), It.IsAny <IByteBuffer>())) .Callback <int, Http2Error, IByteBuffer>((id, err, buf) => ListenerVerifyCallAnswer(calledArray, methodIndex++)); _clientListener .Setup(x => x.OnStreamAdded(It.IsAny <IHttp2Stream>())) .Callback <IHttp2Stream>(s => ListenerExceptionThrower(calledArray, methodIndex)); _clientListener2 .Setup(x => x.OnStreamAdded(It.IsAny <IHttp2Stream>())) .Callback <IHttp2Stream>(s => ListenerVerifyCallAnswer(calledArray, methodIndex++)); // Now we add clientListener2 and exercise all listener functionality try { _client.AddListener(_clientListener2.Object); IHttp2Stream stream = _client.Local.CreateStream(3, false); _clientListener.Verify(x => x.OnStreamAdded(It.IsAny <IHttp2Stream>())); _clientListener2.Verify(x => x.OnStreamAdded(It.IsAny <IHttp2Stream>())); _clientListener.Verify(x => x.OnStreamActive(It.IsAny <IHttp2Stream>())); _clientListener2.Verify(x => x.OnStreamActive(It.IsAny <IHttp2Stream>())); IHttp2Stream reservedStream = _client.Remote.ReservePushStream(2, stream); _clientListener.Verify(x => x.OnStreamActive(It.Is <IHttp2Stream>(s => StreamEq(s, reservedStream))), Times.Never()); _clientListener2.Verify(x => x.OnStreamActive(It.Is <IHttp2Stream>(s => StreamEq(s, reservedStream))), Times.Never()); reservedStream.Open(false); _clientListener.Verify(x => x.OnStreamActive(It.Is <IHttp2Stream>(s => StreamEq(s, reservedStream)))); _clientListener2.Verify(x => x.OnStreamActive(It.Is <IHttp2Stream>(s => StreamEq(s, reservedStream)))); stream.CloseLocalSide(); _clientListener.Verify(x => x.OnStreamHalfClosed(It.IsAny <IHttp2Stream>())); _clientListener2.Verify(x => x.OnStreamHalfClosed(It.IsAny <IHttp2Stream>())); stream.Close(); _clientListener.Verify(x => x.OnStreamClosed(It.IsAny <IHttp2Stream>())); _clientListener2.Verify(x => x.OnStreamClosed(It.IsAny <IHttp2Stream>())); _clientListener.Verify(x => x.OnStreamRemoved(It.IsAny <IHttp2Stream>())); _clientListener2.Verify(x => x.OnStreamRemoved(It.IsAny <IHttp2Stream>())); _client.GoAwaySent(_client.ConnectionStream.Id, Http2Error.InternalError, Unpooled.Empty); _clientListener.Verify(x => x.OnGoAwaySent(It.IsAny <int>(), It.IsAny <Http2Error>(), It.IsAny <IByteBuffer>())); _clientListener2.Verify(x => x.OnGoAwaySent(It.IsAny <int>(), It.IsAny <Http2Error>(), It.IsAny <IByteBuffer>())); _client.GoAwayReceived(_client.ConnectionStream.Id, Http2Error.InternalError, Unpooled.Empty); _clientListener.Verify(x => x.OnGoAwayReceived(It.IsAny <int>(), It.IsAny <Http2Error>(), It.IsAny <IByteBuffer>())); _clientListener2.Verify(x => x.OnGoAwayReceived(It.IsAny <int>(), It.IsAny <Http2Error>(), It.IsAny <IByteBuffer>())); } finally { _client.RemoveListener(_clientListener2.Object); } }