1
1
using System ;
2
2
using System . Linq ;
3
3
using System . Threading . Tasks ;
4
+ using Cleipnir . ResilientFunctions . CoreRuntime ;
4
5
using Cleipnir . ResilientFunctions . CoreRuntime . Watchdogs ;
5
6
using Cleipnir . ResilientFunctions . Domain ;
6
7
using Cleipnir . ResilientFunctions . Helpers ;
@@ -21,7 +22,8 @@ public async Task SunshineScenario(Task<IFunctionStore> storeTask)
21
22
using var watchdog1 = new ReplicaWatchdog (
22
23
replicaId1 ,
23
24
functionStore ,
24
- checkFrequency : TimeSpan . FromHours ( 1 )
25
+ checkFrequency : TimeSpan . FromHours ( 1 ) ,
26
+ default ( UnhandledExceptionHandler ) !
25
27
) ;
26
28
await watchdog1 . Initialize ( ) ;
27
29
var allReplicas = await store . GetAll ( ) ;
@@ -33,7 +35,8 @@ public async Task SunshineScenario(Task<IFunctionStore> storeTask)
33
35
using var watchdog2 = new ReplicaWatchdog (
34
36
replicaId2 ,
35
37
functionStore ,
36
- checkFrequency : TimeSpan . FromHours ( 1 )
38
+ checkFrequency : TimeSpan . FromHours ( 1 ) ,
39
+ default ( UnhandledExceptionHandler ) !
37
40
) ;
38
41
await watchdog2 . Initialize ( ) ;
39
42
allReplicas = await store . GetAll ( ) ;
@@ -74,7 +77,8 @@ public async Task ReplicaWatchdogStartResultsInAddedReplicaInStore(Task<IFunctio
74
77
using var watchdog1 = new ReplicaWatchdog (
75
78
replicaId1 ,
76
79
functionStore ,
77
- checkFrequency : TimeSpan . FromHours ( 1 )
80
+ checkFrequency : TimeSpan . FromHours ( 1 ) ,
81
+ default ( UnhandledExceptionHandler ) !
78
82
) ;
79
83
await watchdog1 . Start ( ) ;
80
84
var allReplicas = await store . GetAll ( ) ;
@@ -84,7 +88,8 @@ public async Task ReplicaWatchdogStartResultsInAddedReplicaInStore(Task<IFunctio
84
88
using var watchdog2 = new ReplicaWatchdog (
85
89
replicaId2 ,
86
90
functionStore ,
87
- checkFrequency : TimeSpan . FromHours ( 1 )
91
+ checkFrequency : TimeSpan . FromHours ( 1 ) ,
92
+ default ( UnhandledExceptionHandler ) !
88
93
) ;
89
94
await watchdog2 . Start ( ) ;
90
95
allReplicas = await store . GetAll ( ) ;
@@ -103,7 +108,8 @@ public async Task StrikedOutReplicaIsRemovedFromStore(Task<IFunctionStore> store
103
108
using var watchdog1 = new ReplicaWatchdog (
104
109
replicaId1 ,
105
110
functionStore ,
106
- checkFrequency : TimeSpan . FromHours ( 1 )
111
+ checkFrequency : TimeSpan . FromHours ( 1 ) ,
112
+ default ( UnhandledExceptionHandler ) !
107
113
) ;
108
114
await watchdog1 . Initialize ( ) ;
109
115
await watchdog1 . PerformIteration ( ) ;
@@ -127,7 +133,8 @@ public async Task RunningWatchdogUpdatesItsOwnHeartbeat(Task<IFunctionStore> sto
127
133
using var watchdog1 = new ReplicaWatchdog (
128
134
replicaId1 ,
129
135
functionStore ,
130
- checkFrequency : TimeSpan . FromMilliseconds ( 100 )
136
+ checkFrequency : TimeSpan . FromMilliseconds ( 100 ) ,
137
+ default ( UnhandledExceptionHandler ) !
131
138
) ;
132
139
133
140
await watchdog1 . Start ( ) ;
@@ -152,9 +159,9 @@ public async Task ReplicaIdOffsetIfCalculatedCorrectly(Task<IFunctionStore> stor
152
159
var replicaId2 = new ClusterInfo ( Guid . Parse ( "20000000-0000-0000-0000-000000000000" ) . ToReplicaId ( ) ) ;
153
160
var replicaId3 = new ClusterInfo ( Guid . Parse ( "30000000-0000-0000-0000-000000000000" ) . ToReplicaId ( ) ) ;
154
161
155
- var watchdog1 = new ReplicaWatchdog ( replicaId1 , store , checkFrequency : TimeSpan . FromHours ( 1 ) ) ;
156
- var watchdog2 = new ReplicaWatchdog ( replicaId2 , store , checkFrequency : TimeSpan . FromHours ( 1 ) ) ;
157
- var watchdog3 = new ReplicaWatchdog ( replicaId3 , store , checkFrequency : TimeSpan . FromHours ( 1 ) ) ;
162
+ var watchdog1 = new ReplicaWatchdog ( replicaId1 , store , checkFrequency : TimeSpan . FromHours ( 1 ) , default ( UnhandledExceptionHandler ) ! ) ;
163
+ var watchdog2 = new ReplicaWatchdog ( replicaId2 , store , checkFrequency : TimeSpan . FromHours ( 1 ) , default ( UnhandledExceptionHandler ) ! ) ;
164
+ var watchdog3 = new ReplicaWatchdog ( replicaId3 , store , checkFrequency : TimeSpan . FromHours ( 1 ) , default ( UnhandledExceptionHandler ) ! ) ;
158
165
159
166
await watchdog1 . Initialize ( ) ;
160
167
await watchdog2 . Initialize ( ) ;
@@ -178,9 +185,9 @@ public async Task ReplicaIdOffsetIsUpdatedWhenNodeIsAddedAndDeleted(Task<IFuncti
178
185
var cluster2 = new ClusterInfo ( Guid . Parse ( "20000000-0000-0000-0000-000000000000" ) . ToReplicaId ( ) ) ;
179
186
var cluster3 = new ClusterInfo ( Guid . Parse ( "30000000-0000-0000-0000-000000000000" ) . ToReplicaId ( ) ) ;
180
187
181
- var watchdog1 = new ReplicaWatchdog ( cluster1 , functionStore , checkFrequency : TimeSpan . FromHours ( 1 ) ) ;
182
- var watchdog2 = new ReplicaWatchdog ( cluster2 , functionStore , checkFrequency : TimeSpan . FromHours ( 1 ) ) ;
183
- var watchdog3 = new ReplicaWatchdog ( cluster3 , functionStore , checkFrequency : TimeSpan . FromHours ( 1 ) ) ;
188
+ var watchdog1 = new ReplicaWatchdog ( cluster1 , functionStore , checkFrequency : TimeSpan . FromHours ( 1 ) , default ( UnhandledExceptionHandler ) ! ) ;
189
+ var watchdog2 = new ReplicaWatchdog ( cluster2 , functionStore , checkFrequency : TimeSpan . FromHours ( 1 ) , default ( UnhandledExceptionHandler ) ! ) ;
190
+ var watchdog3 = new ReplicaWatchdog ( cluster3 , functionStore , checkFrequency : TimeSpan . FromHours ( 1 ) , default ( UnhandledExceptionHandler ) ! ) ;
184
191
185
192
await watchdog3 . Initialize ( ) ;
186
193
cluster3 . Offset . ShouldBe ( 0 ) ;
@@ -227,9 +234,9 @@ public async Task ActiveReplicasDoNotDeleteEachOther(Task<IFunctionStore> storeT
227
234
var cluster2 = new ClusterInfo ( Guid . Parse ( "20000000-0000-0000-0000-000000000000" ) . ToReplicaId ( ) ) ;
228
235
var cluster3 = new ClusterInfo ( Guid . Parse ( "30000000-0000-0000-0000-000000000000" ) . ToReplicaId ( ) ) ;
229
236
230
- var watchdog1 = new ReplicaWatchdog ( cluster1 , store , checkFrequency : TimeSpan . FromHours ( 1 ) ) ;
231
- var watchdog2 = new ReplicaWatchdog ( cluster2 , store , checkFrequency : TimeSpan . FromHours ( 1 ) ) ;
232
- var watchdog3 = new ReplicaWatchdog ( cluster3 , store , checkFrequency : TimeSpan . FromHours ( 1 ) ) ;
237
+ var watchdog1 = new ReplicaWatchdog ( cluster1 , store , checkFrequency : TimeSpan . FromHours ( 1 ) , default ( UnhandledExceptionHandler ) ! ) ;
238
+ var watchdog2 = new ReplicaWatchdog ( cluster2 , store , checkFrequency : TimeSpan . FromHours ( 1 ) , default ( UnhandledExceptionHandler ) ! ) ;
239
+ var watchdog3 = new ReplicaWatchdog ( cluster3 , store , checkFrequency : TimeSpan . FromHours ( 1 ) , default ( UnhandledExceptionHandler ) ! ) ;
233
240
234
241
await watchdog1 . Initialize ( ) ;
235
242
await watchdog2 . Initialize ( ) ;
@@ -287,7 +294,8 @@ await functionStore.CreateFunction(
287
294
using var watchdog1 = new ReplicaWatchdog (
288
295
replicaId1 ,
289
296
functionStore ,
290
- checkFrequency : TimeSpan . FromHours ( 1 )
297
+ checkFrequency : TimeSpan . FromHours ( 1 ) ,
298
+ default ( UnhandledExceptionHandler ) !
291
299
) ;
292
300
await watchdog1 . Initialize ( ) ;
293
301
await watchdog1 . PerformIteration ( ) ;
@@ -300,4 +308,24 @@ await functionStore.CreateFunction(
300
308
sf . Expires . ShouldBe ( 0 ) ;
301
309
sf . OwnerId . ShouldBeNull ( ) ;
302
310
}
311
+
312
+ public abstract Task ReplicaWatchdogUpdatesHeartbeat ( ) ;
313
+ public async Task ReplicaWatchdogUpdatesHeartbeat ( Task < IFunctionStore > storeTask )
314
+ {
315
+ var functionStore = await storeTask ;
316
+ var replicaStore = functionStore . ReplicaStore ;
317
+
318
+ var replicaId = ReplicaId . NewId ( ) ;
319
+ var clusterInfo = new ClusterInfo ( replicaId ) ;
320
+ using var watchdog = new ReplicaWatchdog ( clusterInfo , functionStore , checkFrequency : TimeSpan . FromMilliseconds ( 10 ) , default ( UnhandledExceptionHandler ) ! ) ;
321
+ await watchdog . Start ( ) ;
322
+
323
+ await Task . Delay ( 100 ) ;
324
+
325
+ var storedReplicas = await replicaStore . GetAll ( ) ;
326
+ storedReplicas . Count . ShouldBe ( 1 ) ;
327
+ storedReplicas . Single ( ) . ReplicaId . ShouldBe ( replicaId ) ;
328
+ storedReplicas . Single ( ) . Heartbeat . ShouldBeGreaterThan ( 1 ) ;
329
+
330
+ }
303
331
}
0 commit comments