Skip to content

Commit

Permalink
Allow re-running test jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonLapounov committed Jul 30, 2022
1 parent f90d18b commit 9eaaab2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
3 changes: 1 addition & 2 deletions eng/testing/RunnerTemplate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ if [[ "$(uname -s)" == "Darwin" ]]; then
# See discussions in:
# https://github.com/dotnet/core-eng/issues/15333
# https://github.com/dotnet/core-eng/issues/15597
#ulimit -c 0
ulimit -c unlimited
ulimit -c 0
fi

elif [[ "$(uname -s)" == "Linux" ]]; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,22 @@ namespace System.Runtime.Tests
{
public class ControlledExecutionTests
{
private const int NumberOfTests = 5;
private static int s_testCounter;

private bool _startedExecution, _caughtException, _finishedExecution;
private Exception _exception;
private CancellationTokenSource _cts;
private volatile int _counter;

private static void FailTheLastTest()
{
if (PlatformDetection.IsNotWindows)
{
Assert.True(s_testCounter < NumberOfTests, "All tests passed");
}
}

// Tests cancellation on timeout. The ThreadAbortException must be mapped to OperationCanceledException.
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotMonoRuntime), nameof(PlatformDetection.IsNotNativeAot))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/72703", TestPlatforms.AnyUnix)]
Expand All @@ -33,9 +44,9 @@ public void CancelOnTimeout()

// Tests that catch blocks are not aborted. The action catches the ThreadAbortException and throws an exception of a different type.
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotMonoRuntime), nameof(PlatformDetection.IsNotNativeAot))]
//[ActiveIssue("https://github.com/dotnet/runtime/issues/72703", TestPlatforms.AnyUnix)]
public void CancelOnTimeout_ThrowFromCatch()
{
s_testCounter++;
Console.WriteLine("CancelOnTimeout_ThrowFromCatch");
var cts = new CancellationTokenSource();
cts.CancelAfter(200);
Expand All @@ -45,25 +56,31 @@ public void CancelOnTimeout_ThrowFromCatch()
Assert.True(_caughtException);
Assert.False(_finishedExecution);
Assert.IsType<TimeoutException>(_exception);

FailTheLastTest();
}

// Tests that finally blocks are not aborted. The action throws an exception from a finally block.
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotMonoRuntime), nameof(PlatformDetection.IsNotNativeAot))]
public void CancelOnTimeout_ThrowFromFinally()
{
s_testCounter++;
Console.WriteLine("CancelOnTimeout_ThrowFromFinally");
var cts = new CancellationTokenSource();
cts.CancelAfter(200);
RunTest(LengthyAction_ThrowFromFinally, cts.Token);

Assert.True(_startedExecution);
Assert.IsType<TimeoutException>(_exception);

FailTheLastTest();
}

// Tests that finally blocks are not aborted. The action throws an exception from a try block.
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotMonoRuntime), nameof(PlatformDetection.IsNotNativeAot))]
public void CancelOnTimeout_Finally()
{
s_testCounter++;
Console.WriteLine("CancelOnTimeout_Finally");
var cts = new CancellationTokenSource();
cts.CancelAfter(200);
Expand All @@ -72,25 +89,31 @@ public void CancelOnTimeout_Finally()
Assert.True(_startedExecution);
Assert.True(_finishedExecution);
Assert.IsType<TimeoutException>(_exception);

FailTheLastTest();
}

// Tests cancellation before calling the Run method
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotMonoRuntime), nameof(PlatformDetection.IsNotNativeAot))]
public void CancelBeforeRun()
{
s_testCounter++;
Console.WriteLine("CancelBeforeRun");
var cts = new CancellationTokenSource();
cts.Cancel();
Thread.Sleep(100);
RunTest(LengthyAction, cts.Token);

Assert.IsType<OperationCanceledException>(_exception);

FailTheLastTest();
}

// Tests cancellation by the action itself
[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotMonoRuntime), nameof(PlatformDetection.IsNotNativeAot))]
public void CancelItself()
{
s_testCounter++;
Console.WriteLine("CancelItself");
_cts = new CancellationTokenSource();
RunTest(Action_CancelItself, _cts.Token);
Expand All @@ -99,6 +122,8 @@ public void CancelItself()
Assert.False(_finishedExecution);
Assert.IsType<AggregateException>(_exception);
Assert.IsType<ThreadAbortException>(_exception.InnerException);

FailTheLastTest();
}

private void RunTest(Action action, CancellationToken cancellationToken)
Expand Down

0 comments on commit 9eaaab2

Please sign in to comment.