From 473d4381cabee52c98ff2b2a570b1d1a4321368d Mon Sep 17 00:00:00 2001 From: Nikolay Borisenko <22616990+nvborisenko@users.noreply.github.com> Date: Tue, 12 Mar 2024 13:18:03 +0300 Subject: [PATCH] Migrate to async bindings to fix compilation warnings --- .../LogHandler/ContextAwareLogHandler.cs | 14 ++++++------ src/ReportPortal.ReqnrollPlugin/Plugin.cs | 2 +- .../ReportPortal.ReqnrollPlugin.csproj | 2 +- .../ReportPortalHooks.cs | 6 +---- .../SafeBindingInvoker.cs | 22 +++---------------- ...tal.ReqnrollPlugin.IntegrationTests.csproj | 7 +++--- .../ReportPortal.config.json | 2 +- 7 files changed, 17 insertions(+), 38 deletions(-) diff --git a/src/ReportPortal.ReqnrollPlugin/LogHandler/ContextAwareLogHandler.cs b/src/ReportPortal.ReqnrollPlugin/LogHandler/ContextAwareLogHandler.cs index d06dee3..fbd0eed 100644 --- a/src/ReportPortal.ReqnrollPlugin/LogHandler/ContextAwareLogHandler.cs +++ b/src/ReportPortal.ReqnrollPlugin/LogHandler/ContextAwareLogHandler.cs @@ -16,6 +16,13 @@ public class ContextAwareLogHandler : ICommandsListener { private readonly ITraceLogger _traceLogger = TraceLogManager.Instance.GetLogger(); + private readonly Dictionary _nestedStepStatusMap = new Dictionary { + { 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; @@ -170,12 +177,5 @@ public ITestReporter GetCurrentTestReporter() return testReporter; } - - private Dictionary _nestedStepStatusMap = new Dictionary { - { LogScopeStatus.InProgress, Status.InProgress }, - { LogScopeStatus.Passed, Status.Passed }, - { LogScopeStatus.Failed, Status.Failed }, - { LogScopeStatus.Skipped,Status.Skipped } - }; } } diff --git a/src/ReportPortal.ReqnrollPlugin/Plugin.cs b/src/ReportPortal.ReqnrollPlugin/Plugin.cs index 2854dd3..1358114 100644 --- a/src/ReportPortal.ReqnrollPlugin/Plugin.cs +++ b/src/ReportPortal.ReqnrollPlugin/Plugin.cs @@ -35,7 +35,7 @@ public void Initialize(RuntimePluginEvents runtimePluginEvents, RuntimePluginPar runtimePluginEvents.CustomizeGlobalDependencies += (sender, e) => { e.ReqnrollConfiguration.AdditionalStepAssemblies.Add("ReportPortal.ReqnrollPlugin"); - e.ObjectContainer.RegisterTypeAs(); + e.ObjectContainer.RegisterTypeAs(); }; runtimePluginEvents.CustomizeScenarioDependencies += (sender, e) => diff --git a/src/ReportPortal.ReqnrollPlugin/ReportPortal.ReqnrollPlugin.csproj b/src/ReportPortal.ReqnrollPlugin/ReportPortal.ReqnrollPlugin.csproj index 9dab2be..4326ce1 100644 --- a/src/ReportPortal.ReqnrollPlugin/ReportPortal.ReqnrollPlugin.csproj +++ b/src/ReportPortal.ReqnrollPlugin/ReportPortal.ReqnrollPlugin.csproj @@ -25,7 +25,7 @@ contentfiles;analyzers; - + diff --git a/src/ReportPortal.ReqnrollPlugin/ReportPortalHooks.cs b/src/ReportPortal.ReqnrollPlugin/ReportPortalHooks.cs index 144ef3c..6fd12a1 100644 --- a/src/ReportPortal.ReqnrollPlugin/ReportPortalHooks.cs +++ b/src/ReportPortal.ReqnrollPlugin/ReportPortalHooks.cs @@ -83,17 +83,13 @@ private static IConfiguration Initialize() ReportPortalAddin.OnInitializing(typeof(ReportPortalHooks), args); - var uri = Plugin.Config.GetValue(ConfigurationPath.ServerUrl); - var project = Plugin.Config.GetValue(ConfigurationPath.ServerProject); ; - var uuid = Plugin.Config.GetValue(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; diff --git a/src/ReportPortal.ReqnrollPlugin/SafeBindingInvoker.cs b/src/ReportPortal.ReqnrollPlugin/SafeBindingInvoker.cs index bc5c3d3..d0f6b89 100644 --- a/src/ReportPortal.ReqnrollPlugin/SafeBindingInvoker.cs +++ b/src/ReportPortal.ReqnrollPlugin/SafeBindingInvoker.cs @@ -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 { @@ -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 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) { @@ -49,20 +44,9 @@ public override object InvokeBinding(IBinding binding, IContextManager contextMa || 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; } diff --git a/test/ReportPortal.ReqnrollPlugin.Tests/ReportPortal.ReqnrollPlugin.IntegrationTests.csproj b/test/ReportPortal.ReqnrollPlugin.Tests/ReportPortal.ReqnrollPlugin.IntegrationTests.csproj index c29aae2..e62cb2f 100644 --- a/test/ReportPortal.ReqnrollPlugin.Tests/ReportPortal.ReqnrollPlugin.IntegrationTests.csproj +++ b/test/ReportPortal.ReqnrollPlugin.Tests/ReportPortal.ReqnrollPlugin.IntegrationTests.csproj @@ -8,13 +8,12 @@ - - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + diff --git a/test/ReportPortal.ReqnrollPlugin.Tests/ReportPortal.config.json b/test/ReportPortal.ReqnrollPlugin.Tests/ReportPortal.config.json index fb32b32..975d340 100644 --- a/test/ReportPortal.ReqnrollPlugin.Tests/ReportPortal.config.json +++ b/test/ReportPortal.ReqnrollPlugin.Tests/ReportPortal.config.json @@ -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": {