-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Crash app on OutOfMemoryException by default
- Loading branch information
1 parent
75426c6
commit e7ad2d4
Showing
7 changed files
with
148 additions
and
8 deletions.
There are no files selected for viewing
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
110 changes: 110 additions & 0 deletions
110
Vostok.Applications.Scheduled.Tests/ScheduledActionRunner_Tests.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,110 @@ | ||
using System; | ||
using System.Threading; | ||
using FluentAssertions; | ||
using NUnit.Framework; | ||
using Vostok.Commons.Time; | ||
using Vostok.Logging.Abstractions; | ||
using Vostok.Tracing.Abstractions; | ||
|
||
namespace Vostok.Applications.Scheduled.Tests; | ||
|
||
[TestFixture] | ||
internal class ScheduledActionRunner_Tests | ||
{ | ||
[Test] | ||
public void RunAsync_should_throw_when_CrashOnPayloadException_true() | ||
{ | ||
var options = new ScheduledActionOptions | ||
{ | ||
CrashOnPayloadException = true | ||
}; | ||
|
||
var action = new ScheduledAction( | ||
"ExceptionThrower", | ||
Scheduler.Periodical(50.Milliseconds()), | ||
options, | ||
_ => throw new InvalidOperationException("Error")); | ||
|
||
var runner = new ScheduledActionRunner(action, new SilentLog(), new DevNullTracer(), diagnostics: null); | ||
|
||
var cts = new CancellationTokenSource(); | ||
cts.CancelAfter(1.Seconds()); | ||
|
||
var run = async () => await runner.RunAsync(cts.Token); | ||
|
||
run.Should().Throw<InvalidOperationException>(); | ||
} | ||
|
||
[Test] | ||
public void RunAsync_should_not_throw_when_CrashOnPayloadException_false() | ||
{ | ||
var options = new ScheduledActionOptions | ||
{ | ||
CrashOnPayloadException = false | ||
}; | ||
|
||
var action = new ScheduledAction( | ||
"ExceptionThrower", | ||
Scheduler.Periodical(50.Milliseconds()), | ||
options, | ||
_ => throw new InvalidOperationException("Error")); | ||
|
||
var runner = new ScheduledActionRunner(action, new SilentLog(), new DevNullTracer(), diagnostics: null); | ||
|
||
var cts = new CancellationTokenSource(); | ||
cts.CancelAfter(1.Seconds()); | ||
|
||
var run = async () => await runner.RunAsync(cts.Token); | ||
|
||
run.Should().NotThrow(); | ||
} | ||
|
||
[Test] | ||
public void RunAsync_should_throw_OutOfMemoryException_even_when_CrashOnPayloadException_false() | ||
{ | ||
var options = new ScheduledActionOptions | ||
{ | ||
CrashOnPayloadException = false | ||
}; | ||
|
||
var action = new ScheduledAction( | ||
"ExceptionThrower", | ||
Scheduler.Periodical(50.Milliseconds()), | ||
options, | ||
_ => throw new OutOfMemoryException()); | ||
|
||
var runner = new ScheduledActionRunner(action, new SilentLog(), new DevNullTracer(), diagnostics: null); | ||
|
||
var cts = new CancellationTokenSource(); | ||
cts.CancelAfter(1.Seconds()); | ||
|
||
var run = async () => await runner.RunAsync(cts.Token); | ||
|
||
run.Should().Throw<OutOfMemoryException>(); | ||
} | ||
|
||
[Test] | ||
public void RunAsync_should_not_throw_OutOfMemoryException_when_CrashOnPayloadOutOfMemoryException_false() | ||
{ | ||
var options = new ScheduledActionOptions | ||
{ | ||
CrashOnPayloadException = false, | ||
CrashOnPayloadOutOfMemoryException = false | ||
}; | ||
|
||
var action = new ScheduledAction( | ||
"ExceptionThrower", | ||
Scheduler.Periodical(50.Milliseconds()), | ||
options, | ||
_ => throw new OutOfMemoryException()); | ||
|
||
var runner = new ScheduledActionRunner(action, new SilentLog(), new DevNullTracer(), diagnostics: null); | ||
|
||
var cts = new CancellationTokenSource(); | ||
cts.CancelAfter(1.Seconds()); | ||
|
||
var run = async () => await runner.RunAsync(cts.Token); | ||
|
||
run.Should().NotThrow(); | ||
} | ||
} |
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
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
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