public void CloseOnlyOpenSideShouldClose() { IHttp2Stream stream = server.Remote.CreateStream(3, true); stream.CloseLocalSide(); Assert.Equal(Http2StreamState.Closed, stream.State); Assert.Equal(0, server.NumActiveStreams); }
public void CloseLocalWhenOpenShouldSucceed() { IHttp2Stream stream = server.Remote.CreateStream(3, false); stream.CloseLocalSide(); Assert.Equal(Http2StreamState.HalfClosedLocal, stream.State); Assert.Equal(1, server.NumActiveStreams); }
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; this.clientListener .Setup(x => x.OnStreamAdded(It.IsAny <IHttp2Stream>())) .Callback <IHttp2Stream>(s => ListenerExceptionThrower(calledArray, methodIndex)); this.clientListener2 .Setup(x => x.OnStreamAdded(It.IsAny <IHttp2Stream>())) .Callback <IHttp2Stream>(s => ListenerVerifyCallAnswer(calledArray, methodIndex++)); this.clientListener .Setup(x => x.OnStreamActive(It.IsAny <IHttp2Stream>())) .Callback <IHttp2Stream>(s => ListenerExceptionThrower(calledArray, methodIndex)); this.clientListener2 .Setup(x => x.OnStreamActive(It.IsAny <IHttp2Stream>())) .Callback <IHttp2Stream>(s => ListenerVerifyCallAnswer(calledArray, methodIndex++)); this.clientListener .Setup(x => x.OnStreamHalfClosed(It.IsAny <IHttp2Stream>())) .Callback <IHttp2Stream>(s => ListenerExceptionThrower(calledArray, methodIndex)); this.clientListener2 .Setup(x => x.OnStreamHalfClosed(It.IsAny <IHttp2Stream>())) .Callback <IHttp2Stream>(s => ListenerVerifyCallAnswer(calledArray, methodIndex++)); this.clientListener .Setup(x => x.OnStreamClosed(It.IsAny <IHttp2Stream>())) .Callback <IHttp2Stream>(s => ListenerExceptionThrower(calledArray, methodIndex)); this.clientListener2 .Setup(x => x.OnStreamClosed(It.IsAny <IHttp2Stream>())) .Callback <IHttp2Stream>(s => ListenerVerifyCallAnswer(calledArray, methodIndex++)); this.clientListener .Setup(x => x.OnStreamRemoved(It.IsAny <IHttp2Stream>())) .Callback <IHttp2Stream>(s => ListenerExceptionThrower(calledArray, methodIndex)); this.clientListener2 .Setup(x => x.OnStreamRemoved(It.IsAny <IHttp2Stream>())) .Callback <IHttp2Stream>(s => ListenerVerifyCallAnswer(calledArray, methodIndex++)); this.clientListener .Setup(x => x.OnGoAwaySent(It.IsAny <int>(), It.IsAny <Http2Error>(), It.IsAny <IByteBuffer>())) .Callback <int, Http2Error, IByteBuffer>((id, err, buf) => ListenerExceptionThrower(calledArray, methodIndex)); this.clientListener2 .Setup(x => x.OnGoAwaySent(It.IsAny <int>(), It.IsAny <Http2Error>(), It.IsAny <IByteBuffer>())) .Callback <int, Http2Error, IByteBuffer>((id, err, buf) => ListenerVerifyCallAnswer(calledArray, methodIndex++)); this.clientListener .Setup(x => x.OnGoAwayReceived(It.IsAny <int>(), It.IsAny <Http2Error>(), It.IsAny <IByteBuffer>())) .Callback <int, Http2Error, IByteBuffer>((id, err, buf) => ListenerExceptionThrower(calledArray, methodIndex)); this.clientListener2 .Setup(x => x.OnGoAwayReceived(It.IsAny <int>(), It.IsAny <Http2Error>(), It.IsAny <IByteBuffer>())) .Callback <int, Http2Error, IByteBuffer>((id, err, buf) => ListenerVerifyCallAnswer(calledArray, methodIndex++)); this.clientListener .Setup(x => x.OnStreamAdded(It.IsAny <IHttp2Stream>())) .Callback <IHttp2Stream>(s => ListenerExceptionThrower(calledArray, methodIndex)); this.clientListener2 .Setup(x => x.OnStreamAdded(It.IsAny <IHttp2Stream>())) .Callback <IHttp2Stream>(s => ListenerVerifyCallAnswer(calledArray, methodIndex++)); // Now we add clientListener2 and exercise all listener functionality try { this.client.AddListener(this.clientListener2.Object); IHttp2Stream stream = client.Local.CreateStream(3, false); this.clientListener.Verify(x => x.OnStreamAdded(It.IsAny <IHttp2Stream>())); this.clientListener2.Verify(x => x.OnStreamAdded(It.IsAny <IHttp2Stream>())); this.clientListener.Verify(x => x.OnStreamActive(It.IsAny <IHttp2Stream>())); this.clientListener2.Verify(x => x.OnStreamActive(It.IsAny <IHttp2Stream>())); IHttp2Stream reservedStream = client.Remote.ReservePushStream(2, stream); this.clientListener.Verify(x => x.OnStreamActive(It.Is <IHttp2Stream>(s => StreamEq(s, reservedStream))), Times.Never()); this.clientListener2.Verify(x => x.OnStreamActive(It.Is <IHttp2Stream>(s => StreamEq(s, reservedStream))), Times.Never()); reservedStream.Open(false); this.clientListener.Verify(x => x.OnStreamActive(It.Is <IHttp2Stream>(s => StreamEq(s, reservedStream)))); this.clientListener2.Verify(x => x.OnStreamActive(It.Is <IHttp2Stream>(s => StreamEq(s, reservedStream)))); stream.CloseLocalSide(); this.clientListener.Verify(x => x.OnStreamHalfClosed(It.IsAny <IHttp2Stream>())); this.clientListener2.Verify(x => x.OnStreamHalfClosed(It.IsAny <IHttp2Stream>())); stream.Close(); this.clientListener.Verify(x => x.OnStreamClosed(It.IsAny <IHttp2Stream>())); this.clientListener2.Verify(x => x.OnStreamClosed(It.IsAny <IHttp2Stream>())); this.clientListener.Verify(x => x.OnStreamRemoved(It.IsAny <IHttp2Stream>())); this.clientListener2.Verify(x => x.OnStreamRemoved(It.IsAny <IHttp2Stream>())); this.client.GoAwaySent(this.client.ConnectionStream.Id, Http2Error.InternalError, Unpooled.Empty); this.clientListener.Verify(x => x.OnGoAwaySent(It.IsAny <int>(), It.IsAny <Http2Error>(), It.IsAny <IByteBuffer>())); this.clientListener2.Verify(x => x.OnGoAwaySent(It.IsAny <int>(), It.IsAny <Http2Error>(), It.IsAny <IByteBuffer>())); this.client.GoAwayReceived(this.client.ConnectionStream.Id, Http2Error.InternalError, Unpooled.Empty); this.clientListener.Verify(x => x.OnGoAwayReceived(It.IsAny <int>(), It.IsAny <Http2Error>(), It.IsAny <IByteBuffer>())); this.clientListener2.Verify(x => x.OnGoAwayReceived(It.IsAny <int>(), It.IsAny <Http2Error>(), It.IsAny <IByteBuffer>())); } finally { this.client.RemoveListener(this.clientListener2.Object); } }