Skip to content

Commit 6f91665

Browse files
committed
Added utc-now delegate Timeout test
1 parent 9102015 commit 6f91665

File tree

5 files changed

+62
-0
lines changed
  • Core/Cleipnir.ResilientFunctions.Tests
  • Stores
    • MariaDB/Cleipnir.ResilientFunctions.MariaDB.Tests/RFunctionTests
    • PostgreSQL/Cleipnir.ResilientFunctions.PostgreSQL.Tests/RFunctionTests
    • SqlServer/Cleipnir.ResilientFunctions.SqlServer.Tests/RFunctionTests

5 files changed

+62
-0
lines changed

Core/Cleipnir.ResilientFunctions.Tests/InMemoryTests/RFunctionTests/TimeoutTests.cs

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

Core/Cleipnir.ResilientFunctions.Tests/TestTemplates/FunctionTests/TimeoutTests.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Linq;
33
using System.Threading.Tasks;
4+
using Cleipnir.ResilientFunctions.CoreRuntime;
45
using Cleipnir.ResilientFunctions.CoreRuntime.Invocation;
56
using Cleipnir.ResilientFunctions.Domain;
67
using Cleipnir.ResilientFunctions.Domain.Events;
@@ -331,4 +332,49 @@ protected async Task TimeoutsWithSameIdsButDifferentContextsDoNotCollide(Task<IF
331332

332333
unhandledExceptionHandler.ThrownExceptions.Count.ShouldBe(0);
333334
}
335+
336+
public abstract Task ProvidedUtcNowDelegateIsUsedInWatchdog();
337+
protected async Task ProvidedUtcNowDelegateIsUsedInWatchdog(Task<IFunctionStore> storeTask)
338+
{
339+
var store = await storeTask;
340+
var flowId = TestFlowId.Create();
341+
var (flowType, flowInstance) = flowId;
342+
343+
DateTime now = DateTime.UtcNow;
344+
345+
var unhandledExceptionHandler = new UnhandledExceptionCatcher();
346+
using var functionsRegistry = new FunctionsRegistry
347+
(
348+
store,
349+
new Settings(
350+
unhandledExceptionHandler.Catch,
351+
watchdogCheckFrequency: TimeSpan.FromMilliseconds(250),
352+
utcNow: () => now
353+
)
354+
);
355+
356+
var registration = functionsRegistry.RegisterParamless(
357+
flowType,
358+
inner: async Task (workflow) =>
359+
{
360+
await workflow.Delay(now.AddMilliseconds(100));
361+
}
362+
);
363+
await registration.Schedule("SomeInstance");
364+
365+
var cp = await registration.ControlPanel("SomeInstance").ShouldNotBeNullAsync();
366+
await cp.BusyWaitUntil(c => c.Status == Status.Postponed);
367+
368+
await Task.Delay(250);
369+
370+
await cp.ScheduleRestart();
371+
await cp.BusyWaitUntil(c => c.Status == Status.Postponed);
372+
373+
now = now.AddHours(1);
374+
375+
await cp.Refresh();
376+
await cp.BusyWaitUntil(c => c.Status == Status.Succeeded);
377+
378+
unhandledExceptionHandler.ShouldNotHaveExceptions();
379+
}
334380
}

Stores/MariaDB/Cleipnir.ResilientFunctions.MariaDB.Tests/RFunctionTests/TimeoutTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,8 @@ public override Task ExpiredImplicitTimeoutsAreAddedToMessages()
3232
[TestMethod]
3333
public override Task TimeoutsWithSameIdsButDifferentContextsDoNotCollide()
3434
=> TimeoutsWithSameIdsButDifferentContextsDoNotCollide(FunctionStoreFactory.Create());
35+
36+
[TestMethod]
37+
public override Task ProvidedUtcNowDelegateIsUsedInWatchdog()
38+
=> ProvidedUtcNowDelegateIsUsedInWatchdog(FunctionStoreFactory.Create());
3539
}

Stores/PostgreSQL/Cleipnir.ResilientFunctions.PostgreSQL.Tests/RFunctionTests/TimeoutTests.cs

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

Stores/SqlServer/Cleipnir.ResilientFunctions.SqlServer.Tests/RFunctionTests/TimeoutTests.cs

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

0 commit comments

Comments
 (0)