Exemplo n.º 1
0
        public void RemoveAllStreamsWhileIteratingActiveStreams()
        {
            var remote = _client.Remote;
            var local  = _client.Local;

            for (int c = 3, s = 2; c < 5000; c += 2, s += 2)
            {
                local.CreateStream(c, false);
                remote.CreateStream(s, false);
            }
            var promise = _group.GetNext().NewPromise();
            var latch   = new CountdownEvent(_client.NumActiveStreams);

            bool localVisit(IHttp2Stream stream)
            {
                var closeFuture = _client.CloseAsync(promise);

                closeFuture.ContinueWith(t =>
                {
                    Assert.True(t.IsCompleted);
                    latch.SafeSignal();
                }, TaskContinuationOptions.ExecuteSynchronously);
                return(true);
            }

            _client.ForEachActiveStream(localVisit);
            Assert.True(latch.Wait(TimeSpan.FromSeconds(5)));
        }
Exemplo n.º 2
0
        public async Task TestClosedChannelExceptionCarryIOException()
        {
            IOException ioException = new IOException();
            IChannel    channel     = new TestChannel0(ioException);

            var        loopGroup = new DefaultEventLoopGroup(1);
            IEventLoop loop      = loopGroup.GetNext();

            try
            {
                RegisterChannel(loop, channel);
                await channel.ConnectAsync(new IPEndPoint(IPAddress.IPv6Any, 8888));

                try
                {
                    await channel.WriteAndFlushAsync("");
                }
                catch (Exception exc)
                {
                    Assert.Same(ioException, exc);
                }

                AssertClosedChannelException(channel.WriteAndFlushAsync(""), ioException);
                AssertClosedChannelException(channel.WriteAsync(""), ioException);
                AssertClosedChannelException(channel.BindAsync(new IPEndPoint(IPAddress.IPv6Any, 8888)), ioException);
            }
            finally
            {
                channel.CloseAsync().Ignore();
                await loopGroup.ShutdownGracefullyAsync(TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(5));
            }
        }
Exemplo n.º 3
0
        public async Task TestMap()
        {
            IEventLoopGroup group = new DefaultEventLoopGroup();
            LocalAddress    addr  = new LocalAddress(ChannelPoolTestUtils.GetLocalAddrId());

            // Start server
            IChannel sc = await StartServerBootstrapAsync(group, addr);

            Bootstrap cb = new Bootstrap();

            cb.RemoteAddress(addr);
            cb.Group(group).Channel <LocalChannel>();
            var poolMap = new TestChannelPoolMap0(cb);

            IEventLoop loop = group.GetNext();

            Assert.True(poolMap.IsEmpty);
            Assert.Equal(0, poolMap.Count);

            SimpleChannelPool pool = poolMap.Get(loop);

            Assert.Equal(1, poolMap.Count);

            Assert.Same(pool, poolMap.Get(loop));
            Assert.True(poolMap.Remove(loop));
            Assert.False(poolMap.Remove(loop));

            Assert.Equal(0, poolMap.Count);

            await pool.AcquireAsync();

            poolMap.Close();

            await sc.CloseAsync();
        }