-
Notifications
You must be signed in to change notification settings - Fork 302
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DT.AzureStorage: Adding provision to perform graceful shutdown before…
… process kill due to max timeout hits (#536)
- Loading branch information
1 parent
75b5bf3
commit bd61869
Showing
3 changed files
with
185 additions
and
3 deletions.
There are no files selected for viewing
138 changes: 138 additions & 0 deletions
138
Test/DurableTask.AzureStorage.Tests/TimeoutHandlerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace DurableTask.AzureStorage.Tests | ||
{ | ||
/// <summary> | ||
/// Tests for <see cref="TimeoutHandler"/>. | ||
/// </summary> | ||
[TestClass] | ||
public class TimeoutHandlerTests | ||
{ | ||
/// <summary> | ||
/// Ensures that process graceful action is executed before process is killed. | ||
/// </summary> | ||
/// <returns>Task tracking operation.</returns> | ||
[TestMethod] | ||
public async Task EnsureTimeoutHandlerRunsProcessShutdownEventsBeforeProcessKill() | ||
{ | ||
int executionCount = 0; | ||
int killCount = 0; | ||
int shutdownCount = 0; | ||
|
||
Action<string> killAction = (errorString) => killCount++; | ||
typeof(TimeoutHandler) | ||
.GetField("ProcessKillAction", BindingFlags.NonPublic | BindingFlags.Static) | ||
.SetValue(null, killAction); | ||
|
||
// TimeoutHandler at the moment invokes shutdown on 5th call failure. | ||
await TimeoutHandler.ExecuteWithTimeout( | ||
"test", | ||
"account", | ||
new AzureStorageOrchestrationServiceSettings | ||
{ | ||
OnImminentFailFast = (errorString) => | ||
{ | ||
shutdownCount++; | ||
return Task.FromResult(true); | ||
} | ||
}, | ||
async (operationContext, cancellationToken) => | ||
{ | ||
executionCount++; | ||
await Task.Delay(TimeSpan.FromMinutes(3)); | ||
return 1; | ||
}); | ||
|
||
Assert.AreEqual(5, executionCount); | ||
Assert.AreEqual(1, shutdownCount); | ||
Assert.AreEqual(1, killCount); | ||
} | ||
|
||
/// <summary> | ||
/// Ensures that process graceful action is executed and failfast is skipped. | ||
/// </summary> | ||
/// <returns>Task tracking operation.</returns> | ||
[TestMethod] | ||
[ExpectedException(typeof(TimeoutException))] | ||
public async Task EnsureTimeoutHandlerRunsProcessShutdownEventsAndSkipsProcessKill() | ||
{ | ||
int executionCount = 0; | ||
int killCount = 0; | ||
int shutdownCount = 0; | ||
|
||
Action<string> killAction = (errorString) => killCount++; | ||
typeof(TimeoutHandler) | ||
.GetField("ProcessKillAction", BindingFlags.NonPublic | BindingFlags.Static) | ||
.SetValue(null, killAction); | ||
|
||
// TimeoutHandler at the moment invokes shutdown on 5th call failure. | ||
await TimeoutHandler.ExecuteWithTimeout( | ||
"test", | ||
"account", | ||
new AzureStorageOrchestrationServiceSettings | ||
{ | ||
OnImminentFailFast = (errorString) => | ||
{ | ||
shutdownCount++; | ||
return Task.FromResult(false); | ||
} | ||
}, | ||
async (operationContext, cancellationToken) => | ||
{ | ||
executionCount++; | ||
await Task.Delay(TimeSpan.FromMinutes(3)); | ||
return 1; | ||
}); | ||
|
||
Assert.AreEqual(5, executionCount); | ||
Assert.AreEqual(1, shutdownCount); | ||
Assert.AreEqual(0, killCount); | ||
} | ||
|
||
/// <summary> | ||
/// Ensures that process graceful action is executed before process is killed. | ||
/// </summary> | ||
/// <returns>Task tracking operation.</returns> | ||
[TestMethod] | ||
public async Task EnsureTimeoutHandlerExecutesProcessKillIfGracefulShutdownFails() | ||
{ | ||
int executionCount = 0; | ||
int killCount = 0; | ||
int shutdownCount = 0; | ||
|
||
Action<string> killAction = (errorString) => killCount++; | ||
typeof(TimeoutHandler) | ||
.GetField("ProcessKillAction", BindingFlags.NonPublic | BindingFlags.Static) | ||
.SetValue(null, killAction); | ||
|
||
// TimeoutHandler at the moment invokes shutdown on 5th call failure. | ||
await TimeoutHandler.ExecuteWithTimeout( | ||
"test", | ||
"account", | ||
new AzureStorageOrchestrationServiceSettings | ||
{ | ||
OnImminentFailFast = (errorString) => | ||
{ | ||
shutdownCount++; | ||
|
||
throw new Exception("Breaking graceful shutdown"); | ||
} | ||
}, | ||
async (operationContext, cancellationToken) => | ||
{ | ||
executionCount++; | ||
await Task.Delay(TimeSpan.FromMinutes(3)); | ||
return 1; | ||
}); | ||
|
||
Assert.AreEqual(5, executionCount); | ||
Assert.AreEqual(1, shutdownCount); | ||
Assert.AreEqual(1, killCount); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters