diff --git a/Src/IronPythonTest/Cases/CPythonCases.cs b/Src/IronPythonTest/Cases/CPythonCases.cs index d99e77721..eb08df983 100644 --- a/Src/IronPythonTest/Cases/CPythonCases.cs +++ b/Src/IronPythonTest/Cases/CPythonCases.cs @@ -27,7 +27,14 @@ public int StandardCPythonTests(TestInfo testcase) { TestContext.Progress.WriteLine(testcase.Name); // should be printed immediately return executor.RunTest(testcase); } catch (Exception e) { - Assert.Fail(executor.FormatException(e)); + if(e is AggregateException ae) { + ae.Handle((x) => { + Assert.Fail(executor.FormatException(x)); + return true; + }); + } else { + Assert.Fail(executor.FormatException(e)); + } return -1; } } @@ -48,7 +55,14 @@ public int AllCPythonTests(TestInfo testcase) { TestContext.Progress.WriteLine(testcase.Name); // should be printed immediately return executor.RunTest(testcase); } catch (Exception e) { - Assert.Fail(executor.FormatException(e)); + if(e is AggregateException ae) { + ae.Handle((x) => { + Assert.Fail(executor.FormatException(x)); + return true; + }); + } else { + Assert.Fail(executor.FormatException(e)); + } return -1; } } @@ -69,7 +83,14 @@ public int CTypesCPythonTests(TestInfo testcase) { TestContext.Progress.WriteLine(testcase.Name); // should be printed immediately return executor.RunTest(testcase); } catch (Exception e) { - Assert.Fail(executor.FormatException(e)); + if(e is AggregateException ae) { + ae.Handle((x) => { + Assert.Fail(executor.FormatException(x)); + return true; + }); + } else { + Assert.Fail(executor.FormatException(e)); + } return -1; } } diff --git a/Src/IronPythonTest/Cases/CaseExecuter.cs b/Src/IronPythonTest/Cases/CaseExecuter.cs index 86fb93b35..7f702c682 100644 --- a/Src/IronPythonTest/Cases/CaseExecuter.cs +++ b/Src/IronPythonTest/Cases/CaseExecuter.cs @@ -258,24 +258,15 @@ private int GetResult(TestInfo testcase, ScriptEngine engine, ScriptSource sourc engine.GetSysModule().SetVariable("argv", List.FromArrayNoCopy(new object[] { source.Path })); var compiledCode = source.Compile(new IronPython.Compiler.PythonCompilerOptions() { ModuleName = "__main__" }); - var thread = new Thread(() => { + var task = Task.Run(() => { try { - res = engine.Operations.ConvertTo(compiledCode.Execute(scope) ?? 0); + return engine.Operations.ConvertTo(compiledCode.Execute(scope) ?? 0); } catch (SystemExitException ex) { - res = ex.GetExitCode(out object otherCode); - } catch (ThreadAbortException) { - Thread.ResetAbort(); - } - }) { - IsBackground = true - }; - - thread.Start(); - - if (!thread.Join(testcase.Options.Timeout)) { - if(!ClrModule.IsNetCoreApp) { - thread.Abort(); + return ex.GetExitCode(out object otherCode); } + }); + + if (!task.Wait(testcase.Options.Timeout)) { NUnit.Framework.TestContext.Error.WriteLine($"{testcase.Name} timed out after {testcase.Options.Timeout / 1000.0} seconds."); res = -1; } diff --git a/Src/IronPythonTest/Cases/IronPythonCases.cs b/Src/IronPythonTest/Cases/IronPythonCases.cs index 0cb823d23..7d5bbf3b7 100644 --- a/Src/IronPythonTest/Cases/IronPythonCases.cs +++ b/Src/IronPythonTest/Cases/IronPythonCases.cs @@ -21,7 +21,14 @@ public int IronPythonTests(TestInfo testcase) { TestContext.Progress.WriteLine(testcase.Name); return this.executor.RunTest(testcase); } catch (Exception e) { - Assert.Fail(this.executor.FormatException(e)); + if(e is AggregateException ae) { + ae.Handle((x) => { + Assert.Fail(executor.FormatException(x)); + return true; + }); + } else { + Assert.Fail(this.executor.FormatException(e)); + } return -1; } }