예제 #1
0
        public async Task Setup_ShouldRemoveFromCluster_OnDisconnected()
        {
            var            count  = 2;
            FakeConnection client = default;

            _socketServer.OnAccepted = c =>
            {
                switch (count)
                {
                case 2:
                    count--;
                    client = c;
                    return;

                case 1:
                    count--;
                    client?.Dispose();
                    Thread.Sleep(10);     // ensure not called before client removed from cluster
                    return;

                case 0:
                    Assert.Equal(2, _cluster.GetSnapshot().Count);
                    _socketServer.Dispose();     // close server
                    break;
                }
            };

            await _socketServer.Setup();
        }
예제 #2
0
        public async Task Setup_ShouldThrow_OnDisposed()
        {
            var pipe = new FakeDuplexPipe();
            var conn = new FakeConnection {
                Pipe = pipe, Parser = new FakeFrameParser()
            };

            conn.OnCreate = () => conn.Dispose();

            await conn.Setup();

            await Assert.ThrowsAsync <ObjectDisposedException>(async() => await conn.Setup());
        }
예제 #3
0
        public async Task Setup_ShouldInvokeOnDestroyAsync_OnReceiveLoopEnded()
        {
            var pipe = new FakeDuplexPipe();
            var conn = new FakeConnection {
                Pipe = pipe, Parser = new FakeFrameParser()
            };

            conn.OnCreate = () => conn.Dispose();

            await conn.Setup();

            conn.VerifyOnDestroy();
        }
예제 #4
0
        public async Task SendAsync_ShouldThrow_OnDisposed()
        {
            var pipe = new FakeDuplexPipe();
            var conn = new FakeConnection {
                Pipe = pipe, Parser = new FakeFrameParser()
            };

            conn.OnCreate = () => conn.Dispose();

            await conn.Setup();

            await Assert.ThrowsAsync <ObjectDisposedException>(async() => await conn.SendAsync(
                                                                   new Frame <MessageMetadata>(new ReadOnlySequence <byte>(new byte[0]),
                                                                                               new MessageMetadata {
                Length = 0
            })));
        }
예제 #5
0
        public async Task Setup_ShouldReadFrame_OnReceivedData()
        {
            var pipe = new FakeDuplexPipe();
            var conn = new FakeConnection {
                Pipe = pipe, Parser = new FakeFrameParser()
            };
            var setup = conn.Setup();

            conn.OnReceive = metadata =>
            {
                Assert.NotNull(metadata);
                Assert.Equal(4, metadata.Length);
                conn.Dispose();
            };

            //let's write a simple message.
            await pipe.FakeRead(_createMessage(4));

            // then start the receive loop
            await setup;
        }