public void ServiceTaskQueueStopSuceedsWhenQueueIsEmpty() { using (ServiceTaskQueue queue = new ServiceTaskQueue(new MockTracer())) { queue.Stop(); TestServiceTask step = new TestServiceTask(); queue.TryEnqueue(step).ShouldEqual(false); } }
public void ServiceTaskQueueHandlesTwoJobs() { TestServiceTask step1 = new TestServiceTask(); TestServiceTask step2 = new TestServiceTask(); using (ServiceTaskQueue queue = new ServiceTaskQueue(new MockTracer())) { queue.TryEnqueue(step1); queue.TryEnqueue(step2); step1.EventTriggered.WaitOne(this.maxWaitTime).ShouldBeTrue(); step2.EventTriggered.WaitOne(this.maxWaitTime).ShouldBeTrue(); queue.Stop(); step1.NumberOfExecutions.ShouldEqual(1); step2.NumberOfExecutions.ShouldEqual(1); } }
public void ServiceTaskQueueStopsJob() { using (ServiceTaskQueue queue = new ServiceTaskQueue(new MockTracer())) { // This step stops the queue after the step is started, // then checks if Stop() was called. WatchForStopTask watchForStop = new WatchForStopTask(queue); queue.TryEnqueue(watchForStop).ShouldBeTrue(); watchForStop.EventTriggered.WaitOne(this.maxWaitTime).ShouldBeTrue(); watchForStop.SawStopping.ShouldBeTrue(); // Ensure we don't start a job after the Stop() call TestServiceTask watchForStart = new TestServiceTask(); queue.TryEnqueue(watchForStart).ShouldBeFalse(); // This only ensures the event didn't happen within maxWaitTime watchForStart.EventTriggered.WaitOne(this.maxWaitTime).ShouldBeFalse(); queue.Stop(); } }
public WatchForStopTask(ServiceTaskQueue queue) { this.Queue = queue; this.EventTriggered = new ManualResetEvent(false); }