Exemplo n.º 1
0
        public async Task RequestAbortedTokenIsResetBeforeLastWriteAsyncAwaitedWithContentLength()
        {
            _http1Connection.ResponseHeaders["Content-Length"] = "12";

            var original = _http1Connection.RequestAborted;

            // Only first write can be WriteAsyncAwaited
            var startingTask = _http1Connection.InitializeResponseAwaited(Task.CompletedTask, 1);
            await _http1Connection.WriteAsyncAwaited(startingTask, new ArraySegment <byte>(new[] { (byte)'h' }), default(CancellationToken));

            Assert.Equal(original, _http1Connection.RequestAborted);

            foreach (var ch in "ello, worl")
            {
                await _http1Connection.WriteAsync(new ArraySegment <byte>(new[] { (byte)ch }), default(CancellationToken));

                Assert.Equal(original, _http1Connection.RequestAborted);
            }

            await _http1Connection.WriteAsync(new ArraySegment <byte>(new[] { (byte)'d' }), default(CancellationToken));

            Assert.NotEqual(original, _http1Connection.RequestAborted);

            _http1Connection.Abort(new ConnectionAbortedException());

            Assert.False(original.IsCancellationRequested);
            Assert.False(_http1Connection.RequestAborted.IsCancellationRequested);
        }
Exemplo n.º 2
0
        public async Task RequestAbortedTokenIsResetBeforeLastWriteAsyncAwaitedWithContentLength()
        {
            _http1Connection.ResponseHeaders["Content-Length"] = "12";

            // Need to compare WaitHandle ref since CancellationToken is struct
            var original = _http1Connection.RequestAborted.WaitHandle;

            // Only first write can be WriteAsyncAwaited
            var startingTask = _http1Connection.InitializeResponseAwaited(Task.CompletedTask, 1);
            await _http1Connection.WriteAsyncAwaited(startingTask, new ArraySegment <byte>(new[] { (byte)'h' }), default(CancellationToken));

            Assert.Same(original, _http1Connection.RequestAborted.WaitHandle);

            foreach (var ch in "ello, worl")
            {
                await _http1Connection.WriteAsync(new ArraySegment <byte>(new[] { (byte)ch }), default(CancellationToken));

                Assert.Same(original, _http1Connection.RequestAborted.WaitHandle);
            }

            await _http1Connection.WriteAsync(new ArraySegment <byte>(new[] { (byte)'d' }), default(CancellationToken));

            Assert.NotSame(original, _http1Connection.RequestAborted.WaitHandle);
        }