public void Test(int threads, int jobs) { IWorkerMonitor workerMonitor = new TestWorkerMonitor(); IThreadFactory threadFactory = new DefaultThreadFactory(); using (ManualResetEvent stopSignal = new ManualResetEvent(false)) { using (JobQueue <Job> queue = new JobQueue <Job>("Worker queue", stopSignal)) { for (int i = 0; i < threads; i++) { TestWorker worker = new TestWorker(i.ToString(CultureInfo.InvariantCulture), queue, threadFactory, workerMonitor); queue.AddWorker(worker); } queue.StartWorkers(); for (int i = 0; i < jobs; i++) { Job job = new Job("0"); queue.Enqueue(job); } Assert.IsTrue(queue.WaitForQueueToEmpty(TimeSpan.FromSeconds(10))); queue.AssertAllThreadsAlive(); stopSignal.Set(); threadFactory.WaitForAllThreadsToStop(TimeSpan.FromSeconds(5)); Assert.IsTrue(queue.IsEmpty); } } }
public void CheckTriggersQueue() { HeadlessMother mother = new HeadlessMother(); IThreadFactory threadFactory = new DefaultThreadFactory(); IWorkerMonitor workerMonitor = mother.WorkerMonitor; using (ManualResetEvent stopSignal = new ManualResetEvent(false)) { JobQueue <ProjectRelatedJob> buildQueue = new JobQueue <ProjectRelatedJob>("buildQueue", stopSignal); using (CheckTriggersQueueFeeder checkTriggersQueueFeeder = new CheckTriggersQueueFeeder( stopSignal, buildQueue, threadFactory, workerMonitor, mother.ProjectRegistry)) { checkTriggersQueueFeeder.Start(); Thread.Sleep(TimeSpan.FromSeconds(10)); stopSignal.Set(); threadFactory.WaitForAllThreadsToStop(TimeSpan.FromSeconds(5)); } } mother.ProjectRegistry.AssertWasCalled(r => r.ChangeProjectStatus("ProjectPilot", ProjectStatus.CheckingTriggers)); mother.ProjectRegistry.AssertWasCalled(r => r.ChangeProjectStatus("Headless", ProjectStatus.CheckingTriggers)); mother.ProjectRegistry.AssertWasCalled(r => r.ChangeProjectStatus("Flubu", ProjectStatus.CheckingTriggers)); mother.ProjectRegistry.VerifyAllExpectations(); }
public void HeadlessServiceTest() { HeadlessMother mother = new HeadlessMother(); IThreadFactory threadFactory = new DefaultThreadFactory(); mother.ProjectRegistry.Expect(r => r.ChangeProjectStatus("Headless", ProjectStatus.CheckingTriggers)).Repeat .Any(); using (HeadlessService service = new HeadlessService( mother.ProjectRegistry, threadFactory, mother.WorkerMonitor, mother.HeadlessLogger)) { service.Start(); Thread.Sleep(TimeSpan.FromSeconds(20)); service.Stop(TimeSpan.FromSeconds(5)); } mother.ProjectRegistry.AssertWasCalled(r => r.ChangeProjectStatus("Headless", ProjectStatus.Sleeping)); mother.ProjectRegistry.AssertWasNotCalled(r => r.ChangeProjectStatus("ProjectPilot", ProjectStatus.Building)); mother.ProjectRegistry.AssertWasNotCalled(r => r.ChangeProjectStatus("Flubu", ProjectStatus.Building)); mother.ProjectRegistry.VerifyAllExpectations(); }