-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathDelayedStartUpTests.cs
More file actions
165 lines (144 loc) · 6.01 KB
/
Copy pathDelayedStartUpTests.cs
File metadata and controls
165 lines (144 loc) · 6.01 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using Cleipnir.ResilientFunctions.Domain;
using Cleipnir.ResilientFunctions.Helpers;
using Cleipnir.ResilientFunctions.Storage;
using Cleipnir.ResilientFunctions.Tests.Utils;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Shouldly;
namespace Cleipnir.ResilientFunctions.Tests.InMemoryTests.RFunctionTests;
[TestClass]
public class DelayedStartUpTests
{
[TestMethod]
public async Task CrashedWatchDogStartUpIsDelayedByOneSecondSuccessfully()
{
var store = new InMemoryFunctionStore();
var functionId = new FlowId("flowType", "flowInstance");
var stopWatch = new Stopwatch();
stopWatch.Start();
using var rFunctions = new FunctionsRegistry(store, new Settings(
leaseLength: TimeSpan.FromMilliseconds(10),
delayStartup: TimeSpan.FromSeconds(1))
);
var registration = rFunctions.RegisterAction(
functionId.Type,
Task (string param) => Task.CompletedTask
);
await store.CreateFunction(
registration.MapToStoredId(functionId.Instance),
"humanInstanceId",
"hello world".ToJson().ToUtf8Bytes(),
leaseExpiration: DateTime.UtcNow.Ticks,
postponeUntil: 0,
timestamp: DateTime.UtcNow.Ticks,
parent: null,
owner: null
);
await BusyWait.Until(() => store.GetFunction(registration.MapToStoredId(functionId.Instance)).Map(sf => sf?.Status == Status.Succeeded));
stopWatch.Elapsed.ShouldBeGreaterThan(TimeSpan.FromMilliseconds(750));
}
[TestMethod]
public async Task CrashedWatchDogStartUpNotDelayedSuccessfully()
{
var store = new InMemoryFunctionStore();
var flowId = TestFlowId.Create();
var storedType = await store.TypeStore.InsertOrGetStoredType(flowId.Type);
var storedId = StoredId.Create(storedType, flowId.Instance.Value);
await store.CreateFunction(
storedId,
"humanInstanceId",
"hello world".ToJson().ToUtf8Bytes(),
leaseExpiration: DateTime.UtcNow.Ticks,
postponeUntil: 0,
timestamp: DateTime.UtcNow.Ticks,
parent: null,
owner: null
);
var stopWatch = new Stopwatch();
stopWatch.Start();
using var rFunctions = new FunctionsRegistry(store, new Settings(leaseLength: TimeSpan.FromMilliseconds(10)));
rFunctions.RegisterAction(
flowId.Type,
Task (string param) => Task.CompletedTask
);
await BusyWait.Until(() => store.GetFunction(storedId).Map(sf => sf?.Status == Status.Succeeded));
stopWatch.Elapsed.ShouldBeLessThan(TimeSpan.FromMilliseconds(500));
}
[TestMethod]
public async Task PostponedWatchDogStartUpIsDelayedByOneSecondSuccessfully()
{
var store = new InMemoryFunctionStore();
var storedParameter = "hello world".ToJson();
var functionId = new FlowId("flowType", "flowInstance");
var stopWatch = new Stopwatch();
stopWatch.Start();
using var rFunctions = new FunctionsRegistry(store, new Settings(
watchdogCheckFrequency: TimeSpan.FromMilliseconds(10),
delayStartup: TimeSpan.FromSeconds(1))
);
var registration = rFunctions.RegisterAction(
functionId.Type,
Task (string param) => Task.CompletedTask
);
await store.CreateFunction(
registration.MapToStoredId(functionId.Instance),
"humanInstanceId",
storedParameter.ToUtf8Bytes(),
leaseExpiration: DateTime.UtcNow.Ticks,
postponeUntil: null,
timestamp: DateTime.UtcNow.Ticks,
parent: null,
owner: ReplicaId.Empty
);
await store.PostponeFunction(
registration.MapToStoredId(functionId.Instance),
postponeUntil: 0,
timestamp: DateTime.UtcNow.Ticks,
expectedReplica: ReplicaId.Empty,
effects: null,
messages: null,
failIfInterrupted: true,
storageSession: null
).ShouldBeTrueAsync();
await BusyWait.Until(() => store.GetFunction(registration.MapToStoredId(functionId.Instance)).Map(sf => sf?.Status == Status.Succeeded));
stopWatch.Elapsed.ShouldBeGreaterThan(TimeSpan.FromMilliseconds(750));
}
[TestMethod]
public async Task PostponedWatchDogStartUpNotDelayedSuccessfully()
{
var store = new InMemoryFunctionStore();
var storedParameter = "hello world".ToJson().ToUtf8Bytes();
var functionId = new FlowId("flowType", "flowInstance");
var stopWatch = new Stopwatch();
stopWatch.Start();
using var rFunctions = new FunctionsRegistry(store, new Settings(watchdogCheckFrequency: TimeSpan.FromMilliseconds(10)));
var registration = rFunctions.RegisterAction(
functionId.Type,
Task (string param) => Task.CompletedTask
);
await store.CreateFunction(
registration.MapToStoredId(functionId.Instance),
"humanInstanceId",
storedParameter,
leaseExpiration: DateTime.UtcNow.Ticks,
postponeUntil: null,
timestamp: DateTime.UtcNow.Ticks,
parent: null,
owner: ReplicaId.Empty
);
await store.PostponeFunction(
registration.MapToStoredId(functionId.Instance),
postponeUntil: 0,
timestamp: DateTime.UtcNow.Ticks,
expectedReplica: ReplicaId.Empty,
effects: null,
messages: null,
failIfInterrupted: true,
storageSession: null
);
await BusyWait.Until(() => store.GetFunction(registration.MapToStoredId(functionId.Instance)).Map(sf => sf?.Status == Status.Succeeded));
stopWatch.Elapsed.ShouldBeLessThan(TimeSpan.FromMilliseconds(500));
}
}