Пример #1
0
        public void Plug_timeout_on_request_returns_RequestConnectionTimeout_not_ResponseDataTransferTimeout()
        {
            var blockingStream = new MockBlockingStream();

            MockPlug.Register(new XUri("mock://mock"), (plug, verb, uri, request, response) => {
                _log.Debug("blocking request");
                Thread.Sleep(5.Seconds());
                _log.Debug("returning blocking stream");
                response.Return(new DreamMessage(DreamStatus.Ok, null, MimeType.TEXT, -1, blockingStream));
            });
            var stopwatch = Stopwatch.StartNew();

            _log.Debug("calling plug");
            var r = Plug.New(MockPlug.DefaultUri)
                    .WithTimeout(1.Seconds())
                    .Get(new Result <DreamMessage>(5.Seconds())).Block();

            _log.Debug("plug done");
            stopwatch.Stop();
            blockingStream.Unblock();
            Assert.GreaterOrEqual(stopwatch.Elapsed.Seconds, 1);
            Assert.LessOrEqual(stopwatch.Elapsed.Seconds, 3);
            Assert.IsFalse(r.HasTimedOut);
            Assert.IsFalse(r.HasException);
            Assert.AreEqual(DreamStatus.RequestConnectionTimeout, r.Value.Status);
        }
Пример #2
0
        public void Plug_timeout_is_not_used_for_message_memorization()
        {
            var blockingStream = new MockBlockingStream();

            MockPlug.Register(new XUri("mock://mock"), (plug, verb, uri, request, response) => {
                _log.Debug("returning blocking stream");
                response.Return(new DreamMessage(DreamStatus.Ok, null, MimeType.TEXT, -1, blockingStream));
            });
            var stopwatch = Stopwatch.StartNew();
            var msg       = Plug.New(MockPlug.DefaultUri)
                            .WithTimeout(TimeSpan.FromSeconds(1))
                            .InvokeEx(Verb.GET, DreamMessage.Ok(), new Result <DreamMessage>()).Wait();

            stopwatch.Stop();
            _log.Debug("completed request");
            Assert.AreEqual(DreamStatus.Ok, msg.Status);
            Assert.LessOrEqual(stopwatch.Elapsed.Seconds, 1);
            stopwatch = Stopwatch.StartNew();
            _log.Debug("memorizing request");
            var r = msg.Memorize(new Result(1.Seconds())).Block();

            stopwatch.Stop();
            blockingStream.Unblock();
            _log.Debug("completed request memorization");
            Assert.LessOrEqual(stopwatch.Elapsed.Seconds, 2);
            Assert.IsTrue(r.HasTimedOut);
        }
Пример #3
0
 public void Result_timeout_is_used_for_message_memorization_and_results_in_ResponseDataTransferTimeout()
 {
     var blockingStream = new MockBlockingStream();
     MockPlug.Register(new XUri("mock://mock"), (plug, verb, uri, request, response) => {
         _log.Debug("returning blocking stream");
         response.Return(new DreamMessage(DreamStatus.Ok, null, MimeType.TEXT, -1, blockingStream));
     });
     var stopwatch = Stopwatch.StartNew();
     _log.Debug("calling plug");
     var r = Plug.New(MockPlug.DefaultUri)
         .WithTimeout(1.Seconds())
         .Get(new Result<DreamMessage>(3.Seconds())).Block();
     _log.Debug("plug done");
     stopwatch.Stop();
     blockingStream.Unblock();
     Assert.GreaterOrEqual(stopwatch.Elapsed.Seconds, 3);
     Assert.LessOrEqual(stopwatch.Elapsed.Seconds, 4);
     Assert.IsFalse(r.HasTimedOut);
     Assert.IsFalse(r.HasException);
     Assert.AreEqual(DreamStatus.ResponseDataTransferTimeout, r.Value.Status);
 }
Пример #4
0
 public void Plug_timeout_is_not_used_for_message_memorization()
 {
     var blockingStream = new MockBlockingStream();
     MockPlug.Register(new XUri("mock://mock"), (plug, verb, uri, request, response) => {
         _log.Debug("returning blocking stream");
         response.Return(new DreamMessage(DreamStatus.Ok, null, MimeType.TEXT, -1, blockingStream));
     });
     var stopwatch = Stopwatch.StartNew();
     var msg = Plug.New(MockPlug.DefaultUri)
         .WithTimeout(TimeSpan.FromSeconds(1))
         .InvokeEx(Verb.GET, DreamMessage.Ok(), new Result<DreamMessage>()).Wait();
     stopwatch.Stop();
     _log.Debug("completed request");
     Assert.AreEqual(DreamStatus.Ok, msg.Status);
     Assert.LessOrEqual(stopwatch.Elapsed.Seconds, 1);
     stopwatch = Stopwatch.StartNew();
     _log.Debug("memorizing request");
     var r = msg.Memorize(new Result(1.Seconds())).Block();
     stopwatch.Stop();
     blockingStream.Unblock();
     _log.Debug("completed request memorization");
     Assert.LessOrEqual(stopwatch.Elapsed.Seconds, 2);
     Assert.IsTrue(r.HasTimedOut);
 }