Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmh committed Jul 17, 2024
1 parent 785fe1f commit 7da8a47
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Src/UnitTests/CoravelUnitTests/Queuing/QueueMetricTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ public class QueueMetricTests
public async Task TestQueueHasCorrectNumberOfJobsWaiting()
{
Queue queue = new Queue(null, new DispatcherStub());
Action dummy = () => { };

queue.QueueTask(() => Console.Write("test-job-1"));
queue.QueueTask(() => Console.Write("test-job-2"));
queue.QueueTask(() => Console.Write("test-job-3"));
queue.QueueTask(() => dummy());
queue.QueueTask(() => dummy());
queue.QueueTask(() => dummy());

Assert.Equal(3, queue.GetMetrics().WaitingCount());
await queue.ConsumeQueueAsync();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Threading.Tasks;
using Coravel.Scheduling.Schedule;
using Coravel.Scheduling.Schedule.Mutex;
Expand Down Expand Up @@ -58,5 +59,37 @@ public async Task ValidEveryMinute(int day, int hour, int minute, bool shouldRun

Assert.Equal(shouldRun, taskRan);
}

[Theory]
// Sunday
[InlineData("2024-07-14 12:00:00 am", false)]
[InlineData("2024-07-14 12:00:00 pm", false)]
// Monday
[InlineData("2024-07-15 12:00:00 am", true)]
[InlineData("2024-07-15 12:00:00 pm", true)]
// Tuesday
[InlineData("2024-07-16 12:00:00 am", true)]
[InlineData("2024-07-16 12:00:00 pm", true)]
// Wednesday
[InlineData("2024-07-17 12:00:00 am", true)]
[InlineData("2024-07-17 12:00:00 pm", true)]
// Thursday
[InlineData("2024-07-18 12:00:00 am", true)]
[InlineData("2024-07-18 12:00:00 pm", true)]
// Friday
[InlineData("2024-07-19 12:00:00 am", true)]
[InlineData("2024-07-19 12:00:00 pm", true)]
// Saturday
[InlineData("2024-07-20 12:00:00 am", false)]
[InlineData("2024-07-20 12:00:00 pm", false)]
public async Task ValidEveryMinuteWeekday(string dateString, bool shouldRun)
{
var scheduler = new Scheduler(new InMemoryMutex(), new ServiceScopeFactoryStub(), new DispatcherStub());
bool taskRan = false;

scheduler.Schedule(() => taskRan = true).EveryMinute().Weekday();
await scheduler.RunAtAsync(DateTime.Parse(dateString));
Assert.Equal(shouldRun, taskRan);
}
}
}

0 comments on commit 7da8a47

Please sign in to comment.