Catching exceptions in task-factory.
This commit is contained in:
parent
5996c0fa63
commit
db55792f42
|
@ -16,7 +16,14 @@ public class Program
|
|||
Cancellation.Cts.Cancel();
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
runner.Run();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.ToString());
|
||||
}
|
||||
Console.WriteLine("Done.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ namespace ContinuousTests
|
|||
overviewLog.Error("Test infra failure: SingleTestRun failed with " + ex);
|
||||
Environment.Exit(-1);
|
||||
}
|
||||
});
|
||||
}, nameof(SingleTestRun));
|
||||
}
|
||||
|
||||
private void RunTest(Action<bool> resultHandler)
|
||||
|
|
|
@ -5,11 +5,23 @@
|
|||
private readonly object taskLock = new();
|
||||
private readonly List<Task> activeTasks = new List<Task>();
|
||||
|
||||
public void Run(Action action)
|
||||
public void Run(Action action, string name)
|
||||
{
|
||||
lock (taskLock)
|
||||
{
|
||||
activeTasks.Add(Task.Run(action).ContinueWith(CleanupTask, null));
|
||||
activeTasks.Add(Task.Run(() => CatchException(action, name)).ContinueWith(CleanupTask, null));
|
||||
}
|
||||
}
|
||||
|
||||
private void CatchException(Action action, string name)
|
||||
{
|
||||
try
|
||||
{
|
||||
action();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Exception in task '{name}': " + ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ namespace ContinuousTests
|
|||
overviewLog.Error("Test infra failure: TestLoop failed with " + ex);
|
||||
Environment.Exit(-1);
|
||||
}
|
||||
});
|
||||
}, nameof(TestLoop));
|
||||
}
|
||||
|
||||
private void StartTest()
|
||||
|
|
Loading…
Reference in New Issue