Exemple #1
0
        public void Should_not_complete_timeout_if_handler_completes()
        {
            var pongReceived   = new FutureMessage <PongMessage>();
            var continueCalled = new FutureMessage <Task <PongMessage> >();
            var timeoutCalled  = new FutureMessage <PingMessage>();

            TimeSpan timeout = 8.Seconds();

            var ping = new PingMessage();
            ITaskRequest <PingMessage> request = LocalBus.PublishRequestAsync(ping, x =>
            {
                x.HandleTimeout(4.Seconds(), timeoutCalled.Set);

                x.Handle <PongMessage>(pongReceived.Set)
                .ContinueWith(continueCalled.Set);
            });

            pongReceived.IsAvailable(timeout).ShouldBeTrue("The pong was not received");

            request.Task.Wait(timeout).ShouldBeTrue("Task was not completed");

            request.GetResponseTask <PongMessage>().Wait(timeout).ShouldBeTrue("The response task was not completed");

            continueCalled.IsAvailable(timeout).ShouldBeTrue("The continuation was not called");

            timeoutCalled.IsAvailable(2.Seconds()).ShouldBeFalse("The timeout should not have been called");
        }