Пример #1
0
        public void subtask_gets_nested_in_each_task_it_is_started_in()
        {
            // Arrange
            var monitor = new NestingPerformanceMonitor <int>();
            var task1   = 1;
            var task2   = 2;
            var subtask = 3;

            // Act
            monitor.StartTask(task1);
            monitor.StartTask(subtask);
            monitor.StopTask(task1);

            monitor.StartTask(task2);
            monitor.StartTask(subtask);

            var results = monitor.GetResult();

            // Assert
            Assert.AreEqual(2, results.Count);

            Assert.True(results.ContainsKey(task1));
            Assert.NotNull(results[task1].SubtasksDurations);
            Assert.True(results[task1].SubtasksDurations.ContainsKey(subtask));

            Assert.True(results.ContainsKey(task2));
            Assert.NotNull(results[task2].SubtasksDurations);
            Assert.True(results[task2].SubtasksDurations.ContainsKey(subtask));
        }
Пример #2
0
        public void result_for_task_with_subtask_stopped_by_StopCurrentTask_is_correct()
        {
            // Arrange
            var monitor = new NestingPerformanceMonitor <int>();
            var task    = 1;
            var subtask = 2;

            // Act
            monitor.StartTask(task);
            Thread.Sleep(10);

            monitor.StartTask(subtask);
            Thread.Sleep(20);
            monitor.StopCurrentTask();

            Thread.Sleep(10);
            monitor.StopCurrentTask();

            Thread.Sleep(10);

            // Assert
            var result = monitor.GetResult();

            Assert.That(result[task].Duration.TotalMilliseconds, Is.InRange(38, 44));
            Assert.That(result[task].SubtasksDurations[subtask].Duration.TotalMilliseconds, Is.InRange(18, 24));
        }
Пример #3
0
        public void result_for_task_with_two_subtasks_is_correct()
        {
            // Arrange
            var monitor  = new NestingPerformanceMonitor <int>();
            var task     = 1;
            var subtask1 = 2;
            var subtask2 = 3;

            // Act
            monitor.StartTask(task);
            Thread.Sleep(10);

            monitor.StartTask(subtask1);
            Thread.Sleep(20);
            monitor.StopTask(subtask1);

            monitor.StartTask(subtask2);
            Thread.Sleep(20);
            monitor.StopTask(subtask2);

            Thread.Sleep(10);
            monitor.StopTask(task);

            Thread.Sleep(10);

            // Assert
            var result = monitor.GetResult();

            Assert.That(result[task].Duration.TotalMilliseconds, Is.InRange(58, 64));
            Assert.That(result[task].SubtasksDurations[subtask1].Duration.TotalMilliseconds, Is.InRange(18, 24));
            Assert.That(result[task].SubtasksDurations[subtask2].Duration.TotalMilliseconds, Is.InRange(18, 24));
        }
Пример #4
0
        public void stopping_never_started_task_fails()
        {
            // Arrange
            var monitor = new NestingPerformanceMonitor <int>();
            var task    = 1;

            // Assert
            Assert.Catch(() => monitor.StopTask(task));
        }
Пример #5
0
        public void can_start_same_task_twice()
        {
            // Arrange
            var monitor = new NestingPerformanceMonitor <int>();
            var task    = 1;

            // Act
            monitor.StartTask(task);

            // Assert
            monitor.StartTask(task);
        }
Пример #6
0
        public void result_contains_started_task()
        {
            // Arrange
            var monitor = new NestingPerformanceMonitor <int>();
            var task    = 1;

            // Act
            monitor.StartTask(task);
            var results = monitor.GetResult();

            // Assert
            Assert.AreEqual(1, results.Count);
            Assert.True(results.ContainsKey(task));
        }
Пример #7
0
        public void task_without_subtasks_has_null_subtasks()
        {
            // Arrange
            var monitor = new NestingPerformanceMonitor <int>();
            var task    = 1;

            // Act
            monitor.StartTask(task);

            // Assert
            var taskDuration = monitor.GetResult().Single().Value;

            Assert.Null(taskDuration.SubtasksDurations);
        }
Пример #8
0
        public void starting_same_task_twice_does_not_result_in_nesting()
        {
            // Arrange
            var monitor = new NestingPerformanceMonitor <int>();
            var task    = 1;

            // Act
            monitor.StartTask(task);
            monitor.StartTask(task);

            // Assert
            var taskDuration = monitor.GetResult().Single().Value;

            Assert.Null(taskDuration.SubtasksDurations);
        }
Пример #9
0
        public void started_task_is_monitored()
        {
            // Arrange
            var monitor = new NestingPerformanceMonitor <int>();
            var task    = 1;

            // Act
            monitor.StartTask(task);
            Thread.Sleep(10);

            // Assert
            var result = monitor.GetResult();

            Assert.Greater(result[task].Duration.Ticks, 0);
        }
Пример #10
0
        public void result_for_stopped_task_is_correct()
        {
            // Arrange
            var monitor = new NestingPerformanceMonitor <int>();
            var task    = 1;

            // Act
            monitor.StartTask(task);
            Thread.Sleep(20);
            monitor.StopTask(task);
            Thread.Sleep(20);

            // Assert
            var result = monitor.GetResult();

            Assert.That(result[task].Duration.TotalMilliseconds, Is.InRange(18, 24));
        }
Пример #11
0
        public void starting_task_after_stopping_another_task_does_not_result_in_nesting()
        {
            // Arrange
            var monitor = new NestingPerformanceMonitor <int>();
            var task1   = 1;
            var task2   = 2;

            // Act
            monitor.StartTask(task1);
            monitor.StopTask(task1);
            monitor.StartTask(task2);
            var results = monitor.GetResult();

            // Assert
            Assert.AreEqual(2, results.Count);
            Assert.True(results.ContainsKey(task1));
            Assert.True(results.ContainsKey(task2));
            Assert.Null(results[task1].SubtasksDurations);
        }
Пример #12
0
        public void result_contains_subtask()
        {
            // Arrange
            var monitor = new NestingPerformanceMonitor <int>();
            var task    = 1;
            var subtask = 2;

            // Act
            monitor.StartTask(task);
            monitor.StartTask(subtask);
            var result = monitor.GetResult();

            // Assert
            var subtasks = result[task].SubtasksDurations;

            Assert.NotNull(subtasks);
            Assert.AreEqual(1, subtasks.Count);
            Assert.True(subtasks.ContainsKey(subtask));
        }
Пример #13
0
        private NestingPerformanceMonitor <string> Execute()
        {
            // Arrange
            var monitor         = new NestingPerformanceMonitor <string>();
            var task1           = "task1";
            var subtask1_1      = "sub-task 1.1";
            var subsubtask1_1_1 = "sub-sub-task 1.1.1";
            var subsubtask1_1_2 = "sub-sub-task 1.1.2";
            var subtask1_2      = "sub-task 1.2";
            var subsubtask1_2_1 = "sub-sub-task 1.2.1";
            var subsubtask1_2_2 = "sub-sub-task 1.2.2";

            var task2           = "task2";
            var subtask2_1      = "sub-task 2.1";
            var subsubtask2_1_1 = "sub-sub-task 2.1.1";
            var subsubtask2_1_2 = "sub-sub-task 2.1.2";
            var subtask2_2      = "sub-task 2.2";
            var subsubtask2_2_1 = "sub-sub-task 2.2.1";
            var subsubtask2_2_2 = "sub-sub-task 2.2.2";

            // Act - task1:
            monitor.StartTask(task1);
            monitor.StartTask(subtask1_1);             // subtask1_1
            monitor.StartTask(subsubtask1_1_1);
            Thread.Sleep(20);
            monitor.StopTask(subsubtask1_1_1);
            monitor.StartTask(subsubtask1_1_2);
            Thread.Sleep(20);
            monitor.StopTask(subsubtask1_1_2);
            monitor.StopTask(subtask1_1);
            monitor.StartTask(subtask1_2);             // subtask1_2
            monitor.StartTask(subsubtask1_2_1);
            Thread.Sleep(20);
            monitor.StopTask(subsubtask1_2_1);
            monitor.StartTask(subsubtask1_2_2);
            Thread.Sleep(20);
            monitor.StopTask(subsubtask1_2_2);
            monitor.StopTask(subtask1_2);
            monitor.StopTask(task1);

            // Act - task2:
            monitor.StartTask(task2);
            monitor.StartTask(subtask2_1);             // subtask2_1
            monitor.StartTask(subsubtask2_1_1);
            Thread.Sleep(20);
            monitor.StopTask(subsubtask2_1_1);
            monitor.StartTask(subsubtask2_1_2);
            Thread.Sleep(20);
            monitor.StopTask(subsubtask2_1_2);
            monitor.StopTask(subtask2_1);
            monitor.StartTask(subtask2_2);             // subtask2_2
            monitor.StartTask(subsubtask2_2_1);
            Thread.Sleep(20);
            monitor.StopTask(subsubtask2_2_1);
            monitor.StartTask(subsubtask2_2_2);
            Thread.Sleep(20);
            monitor.StopTask(subsubtask2_2_2);
            monitor.StopTask(subtask2_2);
            monitor.StopTask(task2);

            return(monitor);
        }