예제 #1
0
        /// <summary>
        /// Starts the <see cref="Connection"/>.
        /// </summary>
        /// <param name="transport">The transport to use.</param>
        /// <returns>A task that represents when the connection has started.</returns>
        public Task Start(IClientTransport transport)
        {
            if (transport == null)
            {
                throw new ArgumentNullException("transport");
            }

            lock (_startLock)
            {
                if (!ChangeState(ConnectionState.Disconnected, ConnectionState.Connecting))
                {
                    return(_connectTask ?? TaskAsyncHelper.Empty);
                }

                _disconnectCts         = new CancellationTokenSource();
                _startTcs              = new DispatchingTaskCompletionSource <object>();
                _receiveQueueMonitor   = new TaskQueueMonitor(this, DeadlockErrorTimeout);
                _receiveQueue          = new TaskQueue(_startTcs.Task, _receiveQueueMonitor);
                _lastQueuedReceiveTask = TaskAsyncHelper.Empty;

                _transport = transport;

                _connectTask = Negotiate(transport);
            }

            return(_connectTask);
        }
        public void ErrorsAreTriggeredByTimer()
        {
            var mockConnection = new Mock<IConnection>();
            var wh = new ManualResetEventSlim();

            mockConnection.Setup(c => c.OnError(It.IsAny<SlowCallbackException>())).Callback(wh.Set);

            using (var monitor = new TaskQueueMonitor(mockConnection.Object, TimeSpan.FromMilliseconds(100)))
            {
                monitor.TaskStarted();
                Assert.True(wh.Wait(TimeSpan.FromMilliseconds(500)));
            };
        }
        private static void VerifyErrorCount(Times count, Action<TaskQueueMonitor> test)
        {
            var connection = Mock.Of<IConnection>();

            using (var monitor = new TaskQueueMonitor(connection, Timeout.InfiniteTimeSpan))
            {
                test(monitor);
            }

            Mock.Get(connection)
                .Verify(c => c.OnError(It.Is<SlowCallbackException>(e => e.Message == _expectedErrorMessage)), count);
        }
예제 #4
0
        /// <summary>
        /// Starts the <see cref="Connection"/>.
        /// </summary>
        /// <param name="transport">The transport to use.</param>
        /// <returns>A task that represents when the connection has started.</returns>
        public Task Start(IClientTransport transport)
        {
            if (transport == null)
            {
                throw new ArgumentNullException("transport");
            }

            lock (_startLock)
            {
                if (!ChangeState(ConnectionState.Disconnected, ConnectionState.Connecting))
                {
                    return _connectTask ?? TaskAsyncHelper.Empty;
                }

                _disconnectCts = new CancellationTokenSource();
                _startTcs = new TaskCompletionSource<object>();
                _receiveQueueMonitor = new TaskQueueMonitor(this, DeadlockErrorTimeout);
                _receiveQueue = new TaskQueue(_startTcs.Task, _receiveQueueMonitor);
                _lastQueuedReceiveTask = TaskAsyncHelper.Empty;

                _transport = transport;

                _connectTask = Negotiate(transport);
            }

            return _connectTask;
        }