Example #1
0
        public async Task Stop_Logs_WhenOperationCanceledExceptionOccuresInTransport()
        {
            var workerName = $"worker-{DateTime.Now}";

            // arrange
            var transport       = A.Fake <ITransport>();
            var pipeline        = A.Fake <IPipeline>();
            var pipelineInvoker = A.Fake <IPipelineInvoker>();
            var context         = A.Fake <ThreadWorkerSynchronizationContext>();
            var manager         = A.Fake <ParallelOperationsManager>(fake => fake.WithArgumentsForConstructor(() => new ParallelOperationsManager(1)));
            var backOff         = A.Fake <IBackoffStrategy>();
            var logFactory      = A.Fake <IRebusLoggerFactory>();
            var log             = A.Fake <ILog>();
            var timeout         = TimeSpan.FromSeconds(10);
            var owningBus       = A.Fake <RebusBus>();

            A.CallTo(() => logFactory.GetCurrentClassLogger())
            .Returns(log);

            A.CallTo(() => transport.Receive(A <ITransactionContext> ._, A <CancellationToken> ._))
            .Throws(() => new OperationCanceledException("test"));

            // system under test
            var sut = new ThreadWorker(transport, pipeline, pipelineInvoker, workerName, context, manager, backOff, logFactory, timeout, owningBus);


            // act
            await Task.Delay(TimeSpan.FromSeconds(5));

            sut.Stop();

            // assert
            A.CallTo(() => log.Warn("Execution cancelled."))
            .MustHaveHappened();
        }
        public override bool Process(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session)
        {
            if (request.UriPath.StartsWith(Url))
            {
                string board = request.QueryString[UrlParameters.Board].Value;

                if (!string.IsNullOrWhiteSpace(board))
                {
                    BoardWatcher bw = Program.GetBoardWatcher(board);

                    if (bw != null)
                    {
                        for (int i = 0; i < bw.watched_threads.Count; i++)
                        {
                            try
                            {
                                ThreadWorker tw = bw.watched_threads.ElementAt(i).Value;
                                if (!tw.AddedAutomatically)
                                {
                                    tw.Stop();
                                }
                            }
                            catch (System.IndexOutOfRangeException)
                            {
                                break;
                            }
                            catch { }
                        }
                    }
                }
                response.Redirect(MonitoredBoardsPageHandler.Url);
                return(true);
            }

            return(false);
        }
        public async Task Stop_Logs_WhenOperationCanceledExceptionOccuresInTransport(string workerName)
        {
            // arrange
            var transport = A.Fake<ITransport>();
            var pipeline = A.Fake<IPipeline>();
            var pipelineInvoker = A.Fake<IPipelineInvoker>();
            var context = A.Fake<ThreadWorkerSynchronizationContext>();
            var manager = A.Fake<ParallelOperationsManager>(fake => fake.WithArgumentsForConstructor(() => new ParallelOperationsManager(1)));
            var backOff = A.Fake<IBackoffStrategy>();
            var logFactory = A.Fake<IRebusLoggerFactory>();
            var log = A.Fake<ILog>();
            var timeout = TimeSpan.FromSeconds(10);

            A.CallTo(() => logFactory.GetCurrentClassLogger())
                .Returns(log);

            A.CallTo(() => transport.Receive(A<ITransactionContext>._, A<CancellationToken>._))
                .Throws(() => new OperationCanceledException("test"));

            // system under test
            var sut = new ThreadWorker(transport, pipeline, pipelineInvoker, workerName, context, manager, backOff, logFactory, timeout);


            // act
            await Task.Delay(TimeSpan.FromSeconds(5));

            sut.Stop();

            // assert
            A.CallTo(() => log.Warn("Execution cancelled."))
                .MustHaveHappened();
        }