File tree Expand file tree Collapse file tree 7 files changed +74
-2
lines changed
Cleipnir.ResilientFunctions.Tests
InMemoryTests/RFunctionTests
TestTemplates/FunctionTests
Cleipnir.ResilientFunctions/Domain
MariaDB/Cleipnir.ResilientFunctions.MariaDB.Tests/RFunctionTests
PostgreSQL/Cleipnir.ResilientFunctions.PostgreSQL.Tests/RFunctionTests
SqlServer/Cleipnir.ResilientFunctions.SqlServer.Tests/RFunctionTests Expand file tree Collapse file tree 7 files changed +74
-2
lines changed Original file line number Diff line number Diff line change @@ -181,4 +181,8 @@ public override Task CorrelationsCanBeChanged()
181
181
[ TestMethod ]
182
182
public override Task DeleteRemovesFunctionFromAllStores ( )
183
183
=> DeleteRemovesFunctionFromAllStores ( FunctionStoreFactory . Create ( ) ) ;
184
+
185
+ [ TestMethod ]
186
+ public override Task ClearFailedEffectsRemovesFailedEffectBeforeRestart ( )
187
+ => ClearFailedEffectsRemovesFailedEffectBeforeRestart ( FunctionStoreFactory . Create ( ) ) ;
184
188
}
Original file line number Diff line number Diff line change @@ -1699,4 +1699,47 @@ await store.EffectsStore
1699
1699
1700
1700
unhandledExceptionCatcher . ShouldNotHaveExceptions ( ) ;
1701
1701
}
1702
+
1703
+ public abstract Task ClearFailedEffectsRemovesFailedEffectBeforeRestart ( ) ;
1704
+ protected async Task ClearFailedEffectsRemovesFailedEffectBeforeRestart ( Task < IFunctionStore > storeTask )
1705
+ {
1706
+ var unhandledExceptionCatcher = new UnhandledExceptionCatcher ( ) ;
1707
+
1708
+ var store = await storeTask ;
1709
+ var functionId = TestFlowId . Create ( ) ;
1710
+ var ( flowType , flowInstance ) = functionId ;
1711
+ using var functionsRegistry = new FunctionsRegistry ( store , new Settings ( unhandledExceptionCatcher . Catch ) ) ;
1712
+
1713
+ var shouldFail = true ;
1714
+ var registration = functionsRegistry . RegisterParamless (
1715
+ flowType ,
1716
+ inner : async workflow =>
1717
+ {
1718
+ await workflow . Effect . Capture ( ( ) =>
1719
+ {
1720
+ if ( shouldFail )
1721
+ throw new TimeoutException ( "Timeout!" ) ;
1722
+ } ) ;
1723
+ }
1724
+ ) ;
1725
+
1726
+ try
1727
+ {
1728
+ await registration . Invoke ( flowInstance ) ;
1729
+ }
1730
+ catch ( FatalWorkflowException exception )
1731
+ {
1732
+ exception . ErrorType . ShouldBe ( typeof ( TimeoutException ) ) ;
1733
+ }
1734
+
1735
+ var controlPanel = await registration . ControlPanel ( flowInstance . Value ) ;
1736
+ controlPanel . ShouldNotBeNull ( ) ;
1737
+
1738
+ await controlPanel . BusyWaitUntil ( c => c . Status == Status . Failed ) ;
1739
+
1740
+ shouldFail = false ;
1741
+ await controlPanel . Restart ( clearFailedEffects : true ) ;
1742
+
1743
+ unhandledExceptionCatcher . ShouldNotHaveExceptions ( ) ;
1744
+ }
1702
1745
}
Original file line number Diff line number Diff line change @@ -307,15 +307,21 @@ public async Task SaveChanges()
307
307
308
308
public Task Delete ( ) => _invocationHelper . Delete ( StoredId ) ;
309
309
310
- public async Task < TReturn > Restart ( )
310
+ public async Task < TReturn > Restart ( bool clearFailedEffects = false )
311
311
{
312
+ if ( clearFailedEffects )
313
+ await Effects . RemoveFailed ( ) ;
314
+
312
315
if ( _innerParamChanged )
313
316
await SaveChanges ( ) ;
314
317
315
318
return await _invoker . Restart ( StoredId . Instance , Epoch ) ;
316
319
}
317
- public async Task ScheduleRestart ( )
320
+ public async Task ScheduleRestart ( bool clearFailedEffects = false )
318
321
{
322
+ if ( clearFailedEffects )
323
+ await Effects . RemoveFailed ( ) ;
324
+
319
325
if ( _innerParamChanged )
320
326
await SaveChanges ( ) ;
321
327
Original file line number Diff line number Diff line change @@ -53,6 +53,13 @@ public async Task<WorkStatus> GetStatus(EffectId effectId)
53
53
return storedEffects [ effectId ] . WorkStatus ;
54
54
}
55
55
56
+ public async Task RemoveFailed ( )
57
+ {
58
+ foreach ( var effectId in await AllIds )
59
+ if ( await GetStatus ( effectId ) == WorkStatus . Failed )
60
+ await Remove ( effectId ) ;
61
+ }
62
+
56
63
public Task Remove ( string effectId ) => Remove ( effectId . ToEffectId ( ) ) ;
57
64
public async Task Remove ( EffectId effectId )
58
65
{
Original file line number Diff line number Diff line change @@ -180,4 +180,8 @@ public override Task CorrelationsCanBeChanged()
180
180
[ TestMethod ]
181
181
public override Task DeleteRemovesFunctionFromAllStores ( )
182
182
=> DeleteRemovesFunctionFromAllStores ( FunctionStoreFactory . Create ( ) ) ;
183
+
184
+ [ TestMethod ]
185
+ public override Task ClearFailedEffectsRemovesFailedEffectBeforeRestart ( )
186
+ => ClearFailedEffectsRemovesFailedEffectBeforeRestart ( FunctionStoreFactory . Create ( ) ) ;
183
187
}
Original file line number Diff line number Diff line change @@ -181,4 +181,8 @@ public override Task CorrelationsCanBeChanged()
181
181
[ TestMethod ]
182
182
public override Task DeleteRemovesFunctionFromAllStores ( )
183
183
=> DeleteRemovesFunctionFromAllStores ( FunctionStoreFactory . Create ( ) ) ;
184
+
185
+ [ TestMethod ]
186
+ public override Task ClearFailedEffectsRemovesFailedEffectBeforeRestart ( )
187
+ => ClearFailedEffectsRemovesFailedEffectBeforeRestart ( FunctionStoreFactory . Create ( ) ) ;
184
188
}
Original file line number Diff line number Diff line change @@ -182,4 +182,8 @@ public override Task CorrelationsCanBeChanged()
182
182
[ TestMethod ]
183
183
public override Task DeleteRemovesFunctionFromAllStores ( )
184
184
=> DeleteRemovesFunctionFromAllStores ( FunctionStoreFactory . Create ( ) ) ;
185
+
186
+ [ TestMethod ]
187
+ public override Task ClearFailedEffectsRemovesFailedEffectBeforeRestart ( )
188
+ => ClearFailedEffectsRemovesFailedEffectBeforeRestart ( FunctionStoreFactory . Create ( ) ) ;
185
189
}
You can’t perform that action at this time.
0 commit comments