public void Finish(FinishLaunchRequest request) { TraceLogger.Verbose($"Scheduling request to finish launch in {GetHashCode()} proxy instance"); if (StartTask == null) { throw new InsufficientExecutionStackException("The launch wasn't scheduled for starting to finish it properly."); } if (FinishTask != null) { throw new InsufficientExecutionStackException("The launch is already scheduled for finishing."); } var dependentTasks = new List <Task>(); if (ChildTestReporters != null) { dependentTasks.AddRange(ChildTestReporters.Select(tn => tn.FinishTask)); } dependentTasks.Add(StartTask); FinishTask = Task.Factory.ContinueWhenAll(dependentTasks.ToArray(), async(dts) => { try { if (StartTask.IsFaulted) { throw new Exception("Cannot finish launch due starting launch failed.", StartTask.Exception); } if (ChildTestReporters?.Any(ctr => ctr.FinishTask.IsFaulted) == true) { throw new AggregateException("Cannot finish launch due inner items failed to finish.", ChildTestReporters.Where(ctr => ctr.FinishTask.IsFaulted).Select(ctr => ctr.FinishTask.Exception).ToArray()); } if (request.EndTime < LaunchInfo.StartTime) { request.EndTime = LaunchInfo.StartTime; } if (!_isExternalLaunchId) { await _service.FinishLaunchAsync(LaunchInfo.Id, request); } } catch (Exception) { throw; } finally { // clean childs ChildTestReporters = null; } }).Unwrap(); }
public void Finish(FinishLaunchRequest request) { if (request == null) { throw new ArgumentNullException(nameof(request)); } TraceLogger.Verbose($"Scheduling request to finish launch in {GetHashCode()} proxy instance"); if (StartTask == null) { var exp = new InsufficientExecutionStackException("The launch wasn't scheduled for starting to finish it properly."); TraceLogger.Error(exp.ToString()); throw exp; } if (FinishTask != null) { var exp = new InsufficientExecutionStackException("The launch is already scheduled for finishing."); TraceLogger.Error(exp.ToString()); throw exp; } var dependentTasks = new List <Task>(); dependentTasks.Add(StartTask); if (_logsReporter != null) { dependentTasks.Add(_logsReporter.ProcessingTask); } if (_additionalTasks != null) { dependentTasks.AddRange(_additionalTasks); } if (ChildTestReporters != null) { var childTestReporterFinishTasks = ChildTestReporters.Select(tn => tn.FinishTask); if (childTestReporterFinishTasks.Contains(null)) { throw new InsufficientExecutionStackException("Some of child test item(s) are not scheduled to finish yet."); } dependentTasks.AddRange(childTestReporterFinishTasks); } FinishTask = Task.Factory.ContinueWhenAll(dependentTasks.ToArray(), async(dts) => { try { if (StartTask.IsFaulted || StartTask.IsCanceled) { var exp = new Exception("Cannot finish launch due starting launch failed.", StartTask.Exception); if (StartTask.IsCanceled) { exp = new Exception($"Cannot finish launch due timeout while starting it."); } TraceLogger.Error(exp.ToString()); throw exp; } if (ChildTestReporters != null) { var failedChildTestReporters = ChildTestReporters.Where(ctr => ctr.FinishTask.IsFaulted || ctr.FinishTask.IsCanceled); if (failedChildTestReporters.Any()) { var errors = new List <Exception>(); foreach (var failedChildTestReporter in failedChildTestReporters) { if (failedChildTestReporter.FinishTask.IsFaulted) { errors.Add(failedChildTestReporter.FinishTask.Exception); } else if (failedChildTestReporter.FinishTask.IsCanceled) { errors.Add(new Exception($"Cannot finish launch due timeout while finishing test item.")); } } var exp = new AggregateException("Cannot finish launch due finishing of child items failed.", errors); TraceLogger.Error(exp.ToString()); throw exp; } } if (request.EndTime < _launchInfo.StartTime) { request.EndTime = _launchInfo.StartTime; _launchInfo.FinishTime = request.EndTime; } if (!_isExternalLaunchId && _rerunOfUuid == null) { NotifyFinishing(request); await _requestExecuter.ExecuteAsync(() => _service.Launch.FinishAsync(Info.Uuid, request), null).ConfigureAwait(false); NotifyFinished(); } } finally { // clean childs // ChildTestReporters = null; } }, TaskContinuationOptions.PreferFairness).Unwrap(); }
public void Finish(FinishTestItemRequest request) { TraceLogger.Verbose("Scheduling request to finish new test item"); if (StartTask == null) { throw new InsufficientExecutionStackException("The test item wasn't scheduled for starting to finish it properly."); } if (FinishTask != null) { throw new InsufficientExecutionStackException("The test item is already scheduled for finishing."); } var dependentTasks = new List <Task>(); dependentTasks.Add(StartTask); if (_additionalTasks != null) { dependentTasks.AddRange(_additionalTasks); } if (ChildTestReporters != null) { dependentTasks.AddRange(ChildTestReporters.Select(tn => tn.FinishTask)); } FinishTask = Task.Factory.ContinueWhenAll(dependentTasks.ToArray(), async(a) => { try { if (StartTask.IsFaulted) { throw new Exception("Cannot finish test item due starting item failed.", StartTask.Exception); } if (ChildTestReporters?.Any(ctr => ctr.FinishTask.IsFaulted) == true) { throw new AggregateException("Cannot finish test item due finishing of child items failed.", ChildTestReporters.Where(ctr => ctr.FinishTask.IsFaulted).Select(ctr => ctr.FinishTask.Exception).ToArray()); } TestInfo.EndTime = request.EndTime; TestInfo.Status = request.Status; if (request.EndTime < TestInfo.StartTime) { request.EndTime = TestInfo.StartTime; } await _service.FinishTestItemAsync(TestInfo.Id, request); } catch (Exception) { throw; } finally { // clean up childs ChildTestReporters = null; // clean up addition tasks _additionalTasks = null; } }).Unwrap(); }