public void SendReceiveAndVerify_keeps_SendTimeout_ReceiveTimeout()
        {
            var endpoint = TestHelpers.CreateEndpointForTransport(RedFoxTransport.Tcp);
            var socketConfiguration = new SocketConfiguration
            {
                SendTimeout = TimeSpan.FromSeconds(10),
                ReceiveTimeout = TimeSpan.FromSeconds(20)
            };

            var server = new TcpListener(IPAddress.Loopback, endpoint.Port);
            server.Start();
            try
            {
                server.AcceptTcpClientAsync();

                var nodeGreetingVerifier = new NodeGreetingMessageVerifier(NodeType.Requester, NodeType.Responder);

                var socket = (TcpSocket)new SocketFactory().CreateAndConnectAsync(endpoint, NodeType.Responder, socketConfiguration);
                Assert.Throws<TimeoutException>(() => nodeGreetingVerifier.SendReceiveAndVerify(socket, TimeSpan.FromSeconds(2)));

                Assert.AreEqual(socketConfiguration.SendTimeout.ToMillisOrZero(), socket.TcpClient.SendTimeout);
                Assert.AreEqual(socketConfiguration.ReceiveTimeout.ToMillisOrZero(), socket.TcpClient.ReceiveTimeout);
            }
            finally
            {
                server.Stop();
            }
        }
Esempio n. 2
0
        public void SocketConfiguration_applied_to_TcpSocket_when_connecting(NodeType nodeType, bool hasReceiveTimeout)
        {
            var endpoint = TestHelpers.CreateEndpointForTransport(RedFoxTransport.Tcp);
            var socketConfiguration = new SocketConfiguration
            {
                ConnectTimeout = TimeSpan.FromSeconds(5),
                SendBufferSize = 128,
                ReceiveBufferSize = 256,
                SendTimeout = TimeSpan.FromSeconds(1),
                ReceiveTimeout = TimeSpan.FromSeconds(2)
            };

            var server = new TcpListener(IPAddress.Loopback, endpoint.Port);
            server.Start();
            try
            {
                server.AcceptTcpClientAsync();

                var socket = (TcpSocket)new SocketFactory().CreateAndConnectAsync(endpoint, nodeType, socketConfiguration);

                Assert.AreEqual(socketConfiguration.SendBufferSize, socket.TcpClient.SendBufferSize);
                Assert.AreEqual(socketConfiguration.ReceiveBufferSize, socket.TcpClient.ReceiveBufferSize);
                Assert.AreEqual(socketConfiguration.SendTimeout.ToMillisOrZero(), socket.TcpClient.SendTimeout);
                var expectedReceiveTimeout = hasReceiveTimeout ? socketConfiguration.ReceiveTimeout.ToMillisOrZero() : 0;
                Assert.AreEqual(expectedReceiveTimeout, socket.TcpClient.ReceiveTimeout);
            }
            finally
            {
                server.Stop();
            }
        }
        public void ServiceQueueReader_should_obey_ReceiveTimeout_in_socket_configuration_and_disconnects_on_timeout()
        {
            using (var serviceQueue = new ServiceQueue())
            using (var serviceQueueReader = new ServiceQueueReader())
            {
                var endpoint = TestHelpers.CreateEndpointForTransport(RedFoxTransport.Tcp);
                var socketConfiguration = new SocketConfiguration { ReceiveTimeout = TimeSpan.FromMilliseconds(100) };

                serviceQueue.Bind(endpoint);
                serviceQueueReader.Connect(endpoint, socketConfiguration);

                var disconnected = new ManualResetEventSlim();
                serviceQueueReader.Disconnected += disconnected.Set;

                Assert.IsTrue(disconnected.Wait(TimeSpan.FromSeconds(1)));
            }
        }
Esempio n. 4
0
        public void subscriber_should_ignore_ReceiveTimeout_in_socket_configuration_and_must_not_disconnect_on_timeout()
        {
            using (var publisher = new Publisher())
            using (var subscriber = new Subscriber())
            {
                var endpoint = TestHelpers.CreateEndpointForTransport(RedFoxTransport.Tcp);
                var socketConfiguration = new SocketConfiguration { ReceiveTimeout = TimeSpan.FromMilliseconds(100) };

                var disconnected = new ManualResetEventSlim();
                publisher.ClientDisconnected += s => disconnected.Set();

                publisher.Bind(endpoint);
                subscriber.Connect(endpoint, socketConfiguration);

                Assert.IsFalse(disconnected.Wait(TimeSpan.FromSeconds(1)));
            }
        }
Esempio n. 5
0
        public void Requester_Request_should_obey_ReceiveTimeout_in_socket_configuration_and_throw_IOException()
        {
            using (var responder = TestHelpers.CreateTestResponder(1000))
            using (var requester = new Requester())
            {
                var endpoint = TestHelpers.CreateEndpointForTransport(RedFoxTransport.Tcp);
                var socketConfiguration = new SocketConfiguration { ReceiveTimeout = TimeSpan.FromMilliseconds(100) };

                responder.Bind(endpoint);
                requester.Connect(endpoint, socketConfiguration);

                var disconnected = new ManualResetEventSlim();
                requester.Disconnected += disconnected.Set;

                Assert.Throws<IOException>(() => requester.Request(new TestMessage()));
            }
        }
        public void Clone()
        {
            var socketConfiguration = new SocketConfiguration
            {
                ConnectTimeout = TimeSpan.FromSeconds(1),
                ReceiveTimeout = TimeSpan.FromSeconds(2),
                SendTimeout = TimeSpan.FromSeconds(3),
                ReceiveBufferSize = 4,
                SendBufferSize = 5
            };

            var cloned = socketConfiguration.Clone();

            Assert.AreNotSame(socketConfiguration, cloned);

            Assert.AreEqual(socketConfiguration.ConnectTimeout, cloned.ConnectTimeout);
            Assert.AreEqual(socketConfiguration.ReceiveTimeout, cloned.ReceiveTimeout);
            Assert.AreEqual(socketConfiguration.SendTimeout, cloned.SendTimeout);
            Assert.AreEqual(socketConfiguration.ReceiveBufferSize, cloned.ReceiveBufferSize);
            Assert.AreEqual(socketConfiguration.SendBufferSize, cloned.SendBufferSize);
        }
        public void SendReceiveAndVerify_times_out_after_ConnectTimeout()
        {
            var endpoint = TestHelpers.CreateEndpointForTransport(RedFoxTransport.Tcp);
            var socketConfiguration = new SocketConfiguration { ConnectTimeout = TimeSpan.FromSeconds(2) };

            var server = new TcpListener(IPAddress.Loopback, endpoint.Port);
            server.Start();
            try
            {
                server.AcceptTcpClientAsync();

                var nodeGreetingVerifier = new NodeGreetingMessageVerifier(NodeType.Publisher, NodeType.Subscriber);

                var socket = new SocketFactory().CreateAndConnectAsync(endpoint, NodeType.Subscriber, socketConfiguration);

                var sw = Stopwatch.StartNew();
                var task = Task.Factory.StartNew(() =>
                {
                    nodeGreetingVerifier.SendReceiveAndVerify(socket, socketConfiguration.ConnectTimeout);
                });

                var cancellationToken = new CancellationTokenSource(TimeSpan.FromSeconds(5));
                try
                {
                    task.Wait(cancellationToken.Token);
                }
                catch (AggregateException ex)
                {
                    Assert.AreEqual(typeof(TimeoutException), ex.InnerExceptions.Single().GetType());
                }
                Assert.Greater(sw.Elapsed, socketConfiguration.ConnectTimeout);
            }
            finally
            {
                server.Stop();
            }
        }