-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathUtcNowTests.cs
More file actions
44 lines (37 loc) · 1.51 KB
/
Copy pathUtcNowTests.cs
File metadata and controls
44 lines (37 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using Cleipnir.ResilientFunctions.Domain;
using Cleipnir.ResilientFunctions.Storage;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
namespace Cleipnir.Flows.Tests.Flows;
[TestClass]
public class UtcNowTests
{
[TestMethod]
public async Task ProvidedUtcNowDelegateIsUsed()
{
var now = DateTime.UtcNow;
var serviceCollection = new ServiceCollection();
serviceCollection.AddSingleton<UtcNowTestFlow>();
var flowsContainer = new FlowsContainer(
new InMemoryFunctionStore(),
serviceCollection.BuildServiceProvider(),
new Settings(utcNow: () => now, watchdogCheckFrequency: TimeSpan.FromMilliseconds(100))
);
var flows = new Flows<UtcNowTestFlow, DateTime>(nameof(UtcNowTestFlow), flowsContainer);
// Schedule with a postpone time that is already in the past relative to the custom utcNow
// This verifies the utcNow delegate is being used since the delay should be 0
await flows.Schedule("Instance", now.AddMilliseconds(-100));
var cp = await flows.ControlPanel("Instance");
cp.ShouldNotBeNull();
// Flow should complete since postponeUntil is in the past
await cp.WaitForCompletion(allowPostponeAndSuspended: true, maxWait: TimeSpan.FromSeconds(5));
cp.Status.ShouldBe(Status.Succeeded);
}
}
public class UtcNowTestFlow : Flow<DateTime>
{
public override async Task Run(DateTime postponeUntil)
{
await Workflow.Delay(postponeUntil);
}
}