Skip to content

Commit 08c5c81

Browse files
committed
Added ReplicaWatchdogTest
1 parent e2a4cd7 commit 08c5c81

File tree

5 files changed

+51
-0
lines changed

5 files changed

+51
-0
lines changed

Core/Cleipnir.ResilientFunctions.Tests/InMemoryTests/WatchDogsTests/ReplicaWatchdogTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ public override Task ReplicaIdOffsetIfCalculatedCorrectly()
3030
public override Task ReplicaIdOffsetIsUpdatedWhenNodeIsAddedAndDeleted()
3131
=> ReplicaIdOffsetIsUpdatedWhenNodeIsAddedAndDeleted(FunctionStoreFactory.Create());
3232

33+
[TestMethod]
34+
public override Task ActiveReplicasDoNotDeleteEachOther()
35+
=> ActiveReplicasDoNotDeleteEachOther(FunctionStoreFactory.Create());
36+
3337
[TestMethod]
3438
public override Task NonExistingReplicaIdOffsetIsNull()
3539
=> NonExistingReplicaIdOffsetIsNull(FunctionStoreFactory.Create());

Core/Cleipnir.ResilientFunctions.Tests/TestTemplates/WatchDogsTests/ReplicaWatchdogTests.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,41 @@ public async Task ReplicaIdOffsetIsUpdatedWhenNodeIsAddedAndDeleted(Task<IFuncti
220220
cluster3.ReplicaCount.ShouldBe(1);
221221
}
222222

223+
public abstract Task ActiveReplicasDoNotDeleteEachOther();
224+
public async Task ActiveReplicasDoNotDeleteEachOther(Task<IFunctionStore> storeTask)
225+
{
226+
var store = await storeTask.SelectAsync(s => s.ReplicaStore);
227+
228+
var cluster1 = new ClusterInfo(Guid.Parse("10000000-0000-0000-0000-000000000000"));
229+
var cluster2 = new ClusterInfo(Guid.Parse("20000000-0000-0000-0000-000000000000"));
230+
var cluster3 = new ClusterInfo(Guid.Parse("30000000-0000-0000-0000-000000000000"));
231+
232+
var watchdog1 = new ReplicaWatchdog(cluster1, store, checkFrequency: TimeSpan.FromHours(1), onStrikeOut: _ => { });
233+
var watchdog2 = new ReplicaWatchdog(cluster2, store, checkFrequency: TimeSpan.FromHours(1), onStrikeOut: _ => { });
234+
var watchdog3 = new ReplicaWatchdog(cluster3, store, checkFrequency: TimeSpan.FromHours(1), onStrikeOut: _ => { });
235+
236+
await watchdog1.Initialize();
237+
await watchdog2.Initialize();
238+
await watchdog3.Initialize();
239+
240+
await watchdog1.PerformIteration();
241+
await watchdog2.PerformIteration();
242+
243+
await watchdog1.PerformIteration();
244+
await watchdog2.PerformIteration();
245+
246+
await watchdog1.PerformIteration();
247+
await watchdog2.PerformIteration();
248+
249+
await watchdog1.PerformIteration();
250+
await watchdog2.PerformIteration();
251+
252+
var storedReplicas = await store.GetAll();
253+
storedReplicas.Count.ShouldBe(2);
254+
storedReplicas.Any(sr => sr.ReplicaId == cluster1.ReplicaId).ShouldBeTrue();
255+
storedReplicas.Any(sr => sr.ReplicaId == cluster2.ReplicaId).ShouldBeTrue();
256+
}
257+
223258
public abstract Task NonExistingReplicaIdOffsetIsNull();
224259
public Task NonExistingReplicaIdOffsetIsNull(Task<IFunctionStore> storeTask)
225260
{

Stores/MariaDB/Cleipnir.ResilientFunctions.MariaDB.Tests/WatchDogsTests/ReplicaWatchdogTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,8 @@ public override Task NonExistingReplicaIdOffsetIsNull()
3333
[TestMethod]
3434
public override Task ReplicaIdOffsetIsUpdatedWhenNodeIsAddedAndDeleted()
3535
=> ReplicaIdOffsetIsUpdatedWhenNodeIsAddedAndDeleted(FunctionStoreFactory.Create());
36+
37+
[TestMethod]
38+
public override Task ActiveReplicasDoNotDeleteEachOther()
39+
=> ActiveReplicasDoNotDeleteEachOther(FunctionStoreFactory.Create());
3640
}

Stores/PostgreSQL/Cleipnir.ResilientFunctions.PostgreSQL.Tests/WatchDogsTests/ReplicaWatchdogTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,8 @@ public override Task NonExistingReplicaIdOffsetIsNull()
3333
[TestMethod]
3434
public override Task ReplicaIdOffsetIsUpdatedWhenNodeIsAddedAndDeleted()
3535
=> ReplicaIdOffsetIsUpdatedWhenNodeIsAddedAndDeleted(FunctionStoreFactory.Create());
36+
37+
[TestMethod]
38+
public override Task ActiveReplicasDoNotDeleteEachOther()
39+
=> ActiveReplicasDoNotDeleteEachOther(FunctionStoreFactory.Create());
3640
}

Stores/SqlServer/Cleipnir.ResilientFunctions.SqlServer.Tests/WatchDogsTests/ReplicaWatchdogTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,8 @@ public override Task NonExistingReplicaIdOffsetIsNull()
3333
[TestMethod]
3434
public override Task ReplicaIdOffsetIsUpdatedWhenNodeIsAddedAndDeleted()
3535
=> ReplicaIdOffsetIsUpdatedWhenNodeIsAddedAndDeleted(FunctionStoreFactory.Create());
36+
37+
[TestMethod]
38+
public override Task ActiveReplicasDoNotDeleteEachOther()
39+
=> ActiveReplicasDoNotDeleteEachOther(FunctionStoreFactory.Create());
3640
}

0 commit comments

Comments
 (0)