Skip to content

Commit

Permalink
Fix a race condition.
Browse files Browse the repository at this point in the history
  • Loading branch information
vddCore committed May 25, 2024
1 parent 84e12c3 commit e59d046
Showing 1 changed file with 56 additions and 5 deletions.
61 changes: 56 additions & 5 deletions VirtualMachine/Tests/EVIL.Ceres.LanguageTests/Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using EVIL.Ceres.ExecutionEngine;
using EVIL.Ceres.ExecutionEngine.Concurrency;
using EVIL.Ceres.ExecutionEngine.Diagnostics;
using EVIL.Ceres.ExecutionEngine.TypeSystem;
using EVIL.CommonTypes.TypeSystem;

namespace EVIL.Ceres.LanguageTests
{
Expand Down Expand Up @@ -43,6 +45,11 @@ public async Task Run()
await Task.Delay(1);
}

if (Fiber.State == FiberState.Crashed)
{
_processingCrash = true;
}

while (_processingCrash)
{
await Task.Delay(1);
Expand All @@ -51,14 +58,58 @@ public async Task Run()
Fiber.DeImmunize();
}

private void TestCrashHandler(Fiber fiber, Exception exception)
private async void TestCrashHandler(Fiber fiber, Exception exception)
{
_processingCrash = true;

while (!_processingCrash)
{
await Task.Delay(1);
}

Successful = false;
ErrorMessage = exception.Message;
StackTrace.AddRange(fiber.StackTrace(false).Split('\n').Where(x => !string.IsNullOrEmpty(x)));

if (exception is UserUnhandledExceptionException uuee)
{
if (uuee.EvilExceptionObject.Type == DynamicValueType.Error)
{
var e = uuee.EvilExceptionObject.Error!;
if (e["__should_have_thrown"] == true)
{
CallsAnyAsserts = true;

if (e["__threw"] == true)
{
Successful = true;
}
else
{
ErrorMessage = "Expected function to throw, but it was successful.";
}
}
else if (e["__should_not_have_thrown"] != DynamicValue.Nil)
{
CallsAnyAsserts = true;

if (e["__threw"] == false)
{
Successful = true;
}
else
{
ErrorMessage = "Expected function to be successful, but it threw.";
}
}
}
}
else
{
ErrorMessage = exception.Message;
}

if (!Successful)
{
StackTrace.AddRange(fiber.StackTrace(false).Split('\n').Where(x => !string.IsNullOrEmpty(x)));
}

_processingCrash = false;
}

Expand Down

0 comments on commit e59d046

Please sign in to comment.