Skip to content

Commit

Permalink
Migrate to async bindings to fix compilation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
nvborisenko committed Mar 12, 2024
1 parent e6c3f66 commit 473d438
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ public class ContextAwareLogHandler : ICommandsListener
{
private readonly ITraceLogger _traceLogger = TraceLogManager.Instance.GetLogger<ContextAwareLogHandler>();

private readonly Dictionary<LogScopeStatus, Status> _nestedStepStatusMap = new Dictionary<LogScopeStatus, Status> {
{ LogScopeStatus.InProgress, Status.InProgress },
{ LogScopeStatus.Passed, Status.Passed },
{ LogScopeStatus.Failed, Status.Failed },
{ LogScopeStatus.Skipped,Status.Skipped }
};

public void Initialize(ICommandsSource commandsSource)
{
commandsSource.OnBeginLogScopeCommand += CommandsSource_OnBeginLogScopeCommand;
Expand Down Expand Up @@ -170,12 +177,5 @@ public ITestReporter GetCurrentTestReporter()

return testReporter;
}

private Dictionary<LogScopeStatus, Status> _nestedStepStatusMap = new Dictionary<LogScopeStatus, Status> {
{ LogScopeStatus.InProgress, Status.InProgress },
{ LogScopeStatus.Passed, Status.Passed },
{ LogScopeStatus.Failed, Status.Failed },
{ LogScopeStatus.Skipped,Status.Skipped }
};
}
}
2 changes: 1 addition & 1 deletion src/ReportPortal.ReqnrollPlugin/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void Initialize(RuntimePluginEvents runtimePluginEvents, RuntimePluginPar
runtimePluginEvents.CustomizeGlobalDependencies += (sender, e) =>
{
e.ReqnrollConfiguration.AdditionalStepAssemblies.Add("ReportPortal.ReqnrollPlugin");
e.ObjectContainer.RegisterTypeAs<SafeBindingInvoker, IBindingInvoker>();
e.ObjectContainer.RegisterTypeAs<SafeBindingInvoker, IAsyncBindingInvoker>();
};

runtimePluginEvents.CustomizeScenarioDependencies += (sender, e) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<PackageReference Include="ReportPortal.Shared" Version="3.6.2">
<PrivateAssets>contentfiles;analyzers;</PrivateAssets>
</PackageReference>
<PackageReference Include="Reqnroll" Version="1.0.0" />
<PackageReference Include="Reqnroll" Version="1.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 1 addition & 5 deletions src/ReportPortal.ReqnrollPlugin/ReportPortalHooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,13 @@ private static IConfiguration Initialize()

ReportPortalAddin.OnInitializing(typeof(ReportPortalHooks), args);

var uri = Plugin.Config.GetValue<string>(ConfigurationPath.ServerUrl);
var project = Plugin.Config.GetValue<string>(ConfigurationPath.ServerProject); ;
var uuid = Plugin.Config.GetValue<string>(ConfigurationPath.ServerAuthenticationUuid); ;

if (args.Service != null)
{
_service = args.Service as Service;
}
else
{
_service = new Service(new Uri(uri), project, uuid);
_service = new Shared.Reporter.Http.ClientServiceBuilder(Plugin.Config).Build();
}

return args.Config;
Expand Down
22 changes: 3 additions & 19 deletions src/ReportPortal.ReqnrollPlugin/SafeBindingInvoker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
using Reqnroll.Infrastructure;
using Reqnroll.Tracing;
using System;
using System.Diagnostics;
using System.Reflection;
using System.Threading.Tasks;

namespace ReportPortal.ReqnrollPlugin
{
Expand All @@ -17,18 +17,13 @@ public SafeBindingInvoker(ReqnrollConfiguration reqnrollConfiguration, IErrorPro
{
}

public override object InvokeBinding(IBinding binding, IContextManager contextManager, object[] arguments,
ITestTracer testTracer, out TimeSpan duration)
public override async Task<object> InvokeBindingAsync(IBinding binding, IContextManager contextManager, object[] arguments, ITestTracer testTracer, DurationHolder durationHolder)
{
object result = null;

var stopwatch = new Stopwatch();
stopwatch.Start();

try
{
result = base.InvokeBinding(binding, contextManager, arguments,
testTracer, out duration);
result = await base.InvokeBindingAsync(binding, contextManager, arguments, testTracer, durationHolder);
}
catch (Exception ex)
{
Expand All @@ -49,20 +44,9 @@ public SafeBindingInvoker(ReqnrollConfiguration reqnrollConfiguration, IErrorPro
|| hookBinding.HookType == HookType.AfterScenario
|| hookBinding.HookType == HookType.AfterScenarioBlock)
{
stopwatch.Stop();

duration = stopwatch.Elapsed;

testTracer.TraceError(ex, duration);
SetTestError(contextManager.ScenarioContext, ex);
}
}
finally
{
stopwatch.Stop();

duration = stopwatch.Elapsed;
}

return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="NUnit" Version="3.13.1" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0">
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Reqnroll.NUnit" Version="1.0.0" />
<PackageReference Include="Reqnroll.Tools.MsBuild.Generation" Version="1.0.0" />
<PackageReference Include="Reqnroll.NUnit" Version="1.0.1" />
<PackageReference Include="Reqnroll.Tools.MsBuild.Generation" Version="1.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"url": "https://demo.reportportal.io/api/v1",
"project": "default_personal",
"authentication": {
"uuid": "0e80c23b-9676-4b6b-8255-18ef1dece8b5"
"uuid": "req_D8LOiYQHRyah849qROWAchRfMf73snHaSW863sUuKfM-lMrr-4E6-CeyExmEBEwW"
}
},
"launch": {
Expand Down

0 comments on commit 473d438

Please sign in to comment.