コード例 #1
0
            public void Should_enqueue_tasks_more_than_workers_count()
            {
                workersPool.PushTask(WorkerTasks.UnfinishedTask("task 1"));
                workersPool.PushTask(WorkerTasks.UnfinishedTask("task 2"));
                workersPool.PushTask(WorkerTasks.UnfinishedTask("task 3"));
                workersPool.PushTask(WorkerTasks.UnfinishedTask("task 4"));
                workersPool.PushTask(WorkerTasks.UnfinishedTask("task 5"));
                workersPool.PushTask(WorkerTasks.UnfinishedTask("task 6"));
                workersPool.PushTask(WorkerTasks.UnfinishedTask("task 7"));

                workersPool.TasksQueueSize.Should().BeInRange(4, 7);
            }
コード例 #2
0
            public void Should_set_in_progress_tasks_count_while_they_are_executing()
            {
                var startSignal = new CountdownEvent(3);

                workersPool.PushTask(WorkerTasks.UnfinishedTask("task 1", startSignal));
                workersPool.PushTask(WorkerTasks.UnfinishedTask("task 2", startSignal));
                workersPool.PushTask(WorkerTasks.UnfinishedTask("task 3", startSignal));

                startSignal.Wait();
                Thread.Sleep(100);

                var actual = workersPool.TaskInProgress;

                actual.Should().Be(3);
            }
コード例 #3
0
            public void Should_decrease_when_one_of_task_finished()
            {
                var task2FinishSignal = new CountdownEvent(1);
                var startSignal       = new CountdownEvent(3);
                var task2BlockSignal  = new SemaphoreSlim(0);

                workersPool.PushTask(WorkerTasks.UnfinishedTask("task 1", startSignal));
                workersPool.PushTask(WorkerTasks.Task("task 2", task2BlockSignal, startSignal, task2FinishSignal));
                workersPool.PushTask(WorkerTasks.UnfinishedTask("task 3", startSignal));

                startSignal.Wait();
                output.WriteLine("All task started");

                var beforeOneFinish = workersPool.TaskInProgress;

                task2BlockSignal.Release();

                task2FinishSignal.Wait();
                Thread.Sleep(100);
                output.WriteLine("Task 2 finished");

                beforeOneFinish.Should().Be(3);
                workersPool.TaskInProgress.Should().Be(2);
            }