Пример #1
0
        private async Task FirstPairSucceedsSecondPairSucceedsAfterWaitFifthFailsAsync(Policy bulkheadPolicy)
        {
            Console.WriteLine("----------- First pair succeeds second pair succeeds after wait fifth fails -----------");

            var service   = new SlowService(TimeSpan.FromSeconds(2));
            var taskList  = new List <Task>();
            var stopWatch = new Stopwatch();

            stopWatch.Start();
            for (var i = 0; i < 5; ++i)
            {
                var capturedI = i;
                taskList.Add(Task.Run(async() =>
                {
                    try
                    {
                        await bulkheadPolicy.ExecuteAsync(async() =>
                        {
                            Console.WriteLine($"Executing task {capturedI} at {stopWatch.Elapsed}");
                            await service.ThrowBoomerangAsync(capturedI);
                        });
                    }
                    catch (Exception)
                    {
                        Console.WriteLine($"Task {capturedI} failed with BulkheadRejectedException");
                    }
                }));
                await Task.Delay(100); //allow the tasks to run in order for better understanding of the sample
            }

            await Task.WhenAll(taskList);

            stopWatch.Stop();
        }
        public void ServiceIssuesStopTime()
        {
            var serviceUnderTest = new SlowService();

            string result = serviceUnderTest.Delay(100);

            Console.WriteLine(result);
            Assert.IsTrue(result.Contains(" to "));
        }
        public void ServiceIssuesDelayDurationShort()
        {
            var serviceUnderTest = new SlowService();

            string result = serviceUnderTest.Delay(1);

            Console.WriteLine(result);
            Assert.IsTrue(result.Contains("Delay of 1ms"));
        }
        public void ServiceWaitsForAShortWhile()
        {
            var serviceUnderTest = new SlowService();

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            serviceUnderTest.Delay(100);
            stopwatch.Stop();
            Assert.IsTrue(stopwatch.ElapsedMilliseconds >= 100);
        }
Пример #5
0
 public MainWindowViewModel(ModalProgressService modalProgressService, SlowService slowService)
 {
     this.DoWorkCommand        = new DelegateCommand(this.ExecuteDoWork);
     this.modalProgressService = modalProgressService;
     this.slowService          = slowService;
 }