Skip to content

Commit

Permalink
Fallback to launch if log messages are produced without context
Browse files Browse the repository at this point in the history
  • Loading branch information
nvborisenko committed Jun 8, 2022
1 parent cac084b commit d69cbc7
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions src/ReportPortal.NUnitExtension/ReportPortalListener.Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,16 @@ private void HandleLogCommunicationMessage(XElement xElement, AddLogCommunicatio
{
if (message.ContextType == ContextType.Launch)
{
FindFlowItem(testId).TestReporter.LaunchReporter.Log(logRequest);
var flowItem = FindFlowItem(testId);

if (flowItem.TestReporter != null)
{
flowItem.TestReporter.LaunchReporter.Log(logRequest);
}
else
{
_launchReporter.Log(logRequest);
}
}
else
{
Expand Down Expand Up @@ -509,7 +518,16 @@ private void HandleBeginScopeCommunicationMessage(XElement xElement, BeginScopeC
{
if (message.ContextType == ContextType.Launch)
{
nestedStep = FindFlowItem(testId).TestReporter.LaunchReporter.StartChildTestReporter(startTestItemRequest);
var flowItem = FindFlowItem(testId);

if (flowItem.TestReporter != null)
{
nestedStep = flowItem.TestReporter.LaunchReporter.StartChildTestReporter(startTestItemRequest);
}
else
{
nestedStep = _launchReporter?.StartChildTestReporter(startTestItemRequest);
}
}
else
{
Expand Down Expand Up @@ -557,21 +575,24 @@ private void HandleEndScopeCommunicationMessage(EndScopeCommunicationMessage mes
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
private FlowItemInfo FindFlowItem(string id)
{
if (!_flowItems.TryGetValue(id, out var flowItem))
{
throw new Exception($"Unknown execution context for {id}");
}
var flowItem = _flowItems[id];

if (flowItem.TestReporter != null)
{
return flowItem;
}
else
{
return FindFlowItem(flowItem.ParentId);
if (!string.IsNullOrEmpty(flowItem.ParentId))
{
return FindFlowItem(flowItem.ParentId);
}
else
{
return flowItem;
}
}
}

Expand Down

0 comments on commit d69cbc7

Please sign in to comment.