Exemple #1
0
        async Task ValidateSettingReception(
            IReadableByteStream stream, Settings expectedSettings)
        {
            var header = await stream.ReadFrameHeaderWithTimeout();

            Assert.Equal(FrameType.Settings, header.Type);
            Assert.Equal(0, header.Flags);
            Assert.Equal(0u, header.StreamId);
            Assert.Equal(expectedSettings.RequiredSize, header.Length);

            var setBuf = new byte[expectedSettings.RequiredSize];
            await stream.ReadAllWithTimeout(new ArraySegment <byte>(setBuf));

            var settings = new Settings
            {
                EnablePush           = false,
                HeaderTableSize      = 55,
                InitialWindowSize    = 55,
                MaxConcurrentStreams = 55,
                MaxFrameSize         = 55,
                MaxHeaderListSize    = 55,
            };
            var err = settings.UpdateFromData(new ArraySegment <byte>(setBuf));

            Assert.Null(err);
            Assert.Equal(expectedSettings, settings);
        }
        public static async Task AssertSettingsAck(
            this IReadableByteStream stream)
        {
            var header = await stream.ReadFrameHeaderWithTimeout();

            Assert.Equal(FrameType.Settings, header.Type);
            Assert.Equal(0, header.Length);
            Assert.Equal((byte)SettingsFrameFlags.Ack, header.Flags);
            Assert.Equal(0u, header.StreamId);
        }
        public static async Task ReadAndDiscardSettings(
            this IReadableByteStream stream)
        {
            var header = await stream.ReadFrameHeaderWithTimeout();

            Assert.Equal(FrameType.Settings, header.Type);
            Assert.InRange(header.Length, 0, 256);
            await stream.ReadAllWithTimeout(
                new ArraySegment <byte>(new byte[header.Length]));
        }
        public static async Task ReadAndDiscardPong(
            this IReadableByteStream stream)
        {
            var header = await stream.ReadFrameHeaderWithTimeout();

            Assert.Equal(FrameType.Ping, header.Type);
            Assert.Equal(8, header.Length);
            Assert.Equal((byte)PingFrameFlags.Ack, header.Flags);
            Assert.Equal(0u, header.StreamId);
            await stream.ReadAllWithTimeout(
                new ArraySegment <byte>(new byte[8]));
        }
        public static async Task ReadAndDiscardHeaders(
            this IReadableByteStream stream,
            uint expectedStreamId,
            bool expectEndOfStream)
        {
            var header = await stream.ReadFrameHeaderWithTimeout();

            Assert.Equal(FrameType.Headers, header.Type);
            Assert.Equal(expectedStreamId, header.StreamId);
            var isEndOfStream = (header.Flags & (byte)HeadersFrameFlags.EndOfStream) != 0;

            Assert.Equal(expectEndOfStream, isEndOfStream);
            var hbuf = new ArraySegment <byte>(new byte[header.Length]);
            await stream.ReadAllWithTimeout(hbuf);
        }
        public static async Task AssertResetStreamReception(
            this IReadableByteStream stream,
            uint expectedStreamId,
            ErrorCode expectedErrorCode)
        {
            var hdr = await stream.ReadFrameHeaderWithTimeout();

            Assert.Equal(FrameType.ResetStream, hdr.Type);
            Assert.Equal(expectedStreamId, hdr.StreamId);
            Assert.Equal(0, hdr.Flags);
            Assert.Equal(ResetFrameData.Size, hdr.Length);
            var resetBytes = new byte[hdr.Length];
            await stream.ReadAllWithTimeout(new ArraySegment <byte>(resetBytes));

            var resetData = ResetFrameData.DecodeFrom(new ArraySegment <byte>(resetBytes));

            Assert.Equal(expectedErrorCode, resetData.ErrorCode);
        }
        public static async Task AssertWindowUpdate(
            this IReadableByteStream stream,
            uint expectedStreamId,
            int increment)
        {
            var header = await stream.ReadFrameHeaderWithTimeout();

            Assert.Equal(FrameType.WindowUpdate, header.Type);
            Assert.Equal(WindowUpdateData.Size, header.Length);
            Assert.Equal(0, header.Flags);
            Assert.Equal(expectedStreamId, header.StreamId);
            var buf = new byte[WindowUpdateData.Size];
            await stream.ReadAllWithTimeout(new ArraySegment <byte>(buf));

            var wu = WindowUpdateData.DecodeFrom(new ArraySegment <byte>(buf));

            Assert.Equal(increment, wu.WindowSizeIncrement);
        }
        public static async Task AssertGoAwayReception(
            this IReadableByteStream stream,
            ErrorCode expectedErrorCode,
            uint lastStreamId)
        {
            var hdr = await stream.ReadFrameHeaderWithTimeout();

            Assert.Equal(FrameType.GoAway, hdr.Type);
            Assert.Equal(0u, hdr.StreamId);
            Assert.Equal(0, hdr.Flags);
            Assert.InRange(hdr.Length, 8, 256);
            var goAwayBytes = new byte[hdr.Length];
            await stream.ReadAllWithTimeout(new ArraySegment <byte>(goAwayBytes));

            var goAwayData = GoAwayFrameData.DecodeFrom(new ArraySegment <byte>(goAwayBytes));

            Assert.Equal(lastStreamId, goAwayData.Reason.LastStreamId);
            Assert.Equal(expectedErrorCode, goAwayData.Reason.ErrorCode);
        }
        public static async Task ReadAndDiscardData(
            this IReadableByteStream stream,
            uint expectedStreamId,
            bool expectEndOfStream,
            int?expectedAmount)
        {
            var header = await stream.ReadFrameHeaderWithTimeout();

            Assert.Equal(FrameType.Data, header.Type);
            Assert.Equal(expectedStreamId, header.StreamId);
            var isEndOfStream = (header.Flags & (byte)DataFrameFlags.EndOfStream) != 0;

            Assert.Equal(expectEndOfStream, isEndOfStream);
            if (expectedAmount.HasValue)
            {
                Assert.Equal(expectedAmount.Value, header.Length);
            }
            var dataBuf = new ArraySegment <byte>(new byte[header.Length]);
            await stream.ReadAllWithTimeout(dataBuf);
        }