public void Should_Remove_LongRunning_Task_But_Keep_Running() { var name = "longrunning"; var schedule = new Schedule(() => { Thread.Sleep(100); }); schedule.WithName(name).ToRunNow().AndEvery(2).Seconds(); schedule.Execute(); Assert.IsTrue(TaskManager.RunningSchedules.Any(task => task.Name == name)); TaskManager.RemoveTask(name); Assert.IsNull(TaskManager.GetSchedule(name)); Assert.IsTrue(TaskManager.RunningSchedules.Any(task => task.Name == name)); Thread.Sleep(2042); // wait until a second run would normally be executed Assert.IsFalse(TaskManager.RunningSchedules.Any(task => task.Name == name)); }
public void Should_Remove_LongRunning_Task_But_Keep_Running() { // Act var schedule = new Schedule(() => Thread.Sleep(100)); schedule.WithName("remove long running task").ToRunNow().AndEvery(2).Seconds(); schedule.Execute(); // Assert Assert.IsTrue(TaskManager.RunningSchedules.Any(s => s.Name == "remove long running task")); // Act TaskManager.RemoveTask("remove long running task"); // Assert Assert.IsNull(TaskManager.GetSchedule("remove long running task")); Assert.IsTrue(TaskManager.RunningSchedules.Any(s => s.Name == "remove long running task")); Thread.Sleep(2000); Assert.IsFalse(TaskManager.RunningSchedules.Any(s => s.Name == "remove long running task")); }