Skip to content

Commit

Permalink
make MethodExecutor.Execute handle async, #199
Browse files Browse the repository at this point in the history
the entire method execution chain is now async

Signed-off-by: sriv <srikanth.ddit@gmail.com>
  • Loading branch information
sriv committed Feb 6, 2024
1 parent 3045ed1 commit 7259238
Show file tree
Hide file tree
Showing 34 changed files with 215 additions and 212 deletions.
9 changes: 5 additions & 4 deletions integration-test/ExecuteStepProcessorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@


using System.Threading;
using System.Threading.Tasks;
using Gauge.Dotnet.Models;
using Gauge.Dotnet.Processors;
using Gauge.Dotnet.Wrappers;
Expand All @@ -18,7 +19,7 @@ namespace Gauge.Dotnet.IntegrationTests
public class ExecuteStepProcessorTests : IntegrationTestsBase
{
[Test]
public void ShouldExecuteMethodFromRequest()
public async Task ShouldExecuteMethodFromRequest()
{
const string parameterizedStepText = "Step that takes a table {}";
const string stepText = "Step that takes a table <table>";
Expand Down Expand Up @@ -64,15 +65,15 @@ public void ShouldExecuteMethodFromRequest()
}
}
};
var result = executeStepProcessor.Process(message);
var result = await executeStepProcessor.Process(message);

var protoExecutionResult = result.ExecutionResult;
ClassicAssert.IsNotNull(protoExecutionResult);
ClassicAssert.IsFalse(protoExecutionResult.Failed);
}

[Test]
public void ShouldCaptureScreenshotOnFailure()
public async Task ShouldCaptureScreenshotOnFailure()
{
const string stepText = "I throw a serializable exception";
var reflectionWrapper = new ReflectionWrapper();
Expand All @@ -96,7 +97,7 @@ public void ShouldCaptureScreenshotOnFailure()
ActualStepText = stepText
};

var result = executeStepProcessor.Process(message);
var result = await executeStepProcessor.Process(message);
var protoExecutionResult = result.ExecutionResult;

ClassicAssert.IsNotNull(protoExecutionResult);
Expand Down
34 changes: 17 additions & 17 deletions integration-test/ExecutionOrchestratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
*----------------------------------------------------------------*/


using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Gauge.CSharp.Lib;
using Gauge.Dotnet.Models;
using Gauge.Dotnet.Wrappers;
Expand All @@ -20,7 +20,7 @@ namespace Gauge.Dotnet.IntegrationTests
public class ExecutionOrchestratorTests : IntegrationTestsBase
{
[Test]
public void RecoverableIsTrueOnExceptionThrownWhenContinueOnFailure()
public async Task RecoverableIsTrueOnExceptionThrownWhenContinueOnFailure()
{
var reflectionWrapper = new ReflectionWrapper();
var activatorWrapper = new ActivatorWrapper();
Expand All @@ -34,13 +34,13 @@ public void RecoverableIsTrueOnExceptionThrownWhenContinueOnFailure()
new StepExecutor(assemblyLoader, reflectionWrapper, classInstanceManager));
var gaugeMethod = assemblyLoader.GetStepRegistry()
.MethodFor("I throw a serializable exception and continue");
var executionResult = orchestrator.ExecuteStep(gaugeMethod);
var executionResult = await orchestrator.ExecuteStep(gaugeMethod);
ClassicAssert.IsTrue(executionResult.Failed);
ClassicAssert.IsTrue(executionResult.RecoverableError);
}

[Test]
public void ShouldCreateTableFromTargetType()
public async Task ShouldCreateTableFromTargetType()
{
var reflectionWrapper = new ReflectionWrapper();
var activatorWrapper = new ActivatorWrapper();
Expand All @@ -57,12 +57,12 @@ public void ShouldCreateTableFromTargetType()
table.AddRow(new List<string> { "foorow1", "barrow1" });
table.AddRow(new List<string> { "foorow2", "barrow2" });

var executionResult = orchestrator.ExecuteStep(gaugeMethod, SerializeTable(table));
var executionResult = await orchestrator.ExecuteStep(gaugeMethod, SerializeTable(table));
ClassicAssert.False(executionResult.Failed);
}

[Test]
public void ShouldExecuteMethodAndReturnResult()
public async Task ShouldExecuteMethodAndReturnResult()
{
var reflectionWrapper = new ReflectionWrapper();
var activatorWrapper = new ActivatorWrapper();
Expand All @@ -77,12 +77,12 @@ public void ShouldExecuteMethodAndReturnResult()
var gaugeMethod = assemblyLoader.GetStepRegistry()
.MethodFor("A context step which gets executed before every scenario");

var executionResult = orchestrator.ExecuteStep(gaugeMethod);
var executionResult = await orchestrator.ExecuteStep(gaugeMethod);
ClassicAssert.False(executionResult.Failed);
}

[Test]
public void ShouldGetPendingMessages()
public async Task ShouldGetPendingMessages()
{
var reflectionWrapper = new ReflectionWrapper();
var activatorWrapper = new ActivatorWrapper();
Expand All @@ -97,14 +97,14 @@ public void ShouldGetPendingMessages()

var gaugeMethod = assemblyLoader.GetStepRegistry().MethodFor("Say {} to {}");

var executionResult = executionOrchestrator.ExecuteStep(gaugeMethod, "hello", "world");
var executionResult = await executionOrchestrator.ExecuteStep(gaugeMethod, "hello", "world");

ClassicAssert.False(executionResult.Failed);
ClassicAssert.Contains("hello, world!", executionResult.Message);
}

[Test]
public void ShouldExecuteAsyncStepImplementation()
public async Task ShouldExecuteAsyncStepImplementation()
{
var reflectionWrapper = new ReflectionWrapper();
var activatorWrapper = new ActivatorWrapper();
Expand All @@ -119,14 +119,14 @@ public void ShouldExecuteAsyncStepImplementation()

var gaugeMethod = assemblyLoader.GetStepRegistry().MethodFor("Say {} to {} async");

var executionResult = executionOrchestrator.ExecuteStep(gaugeMethod, "hello", "async world");
var executionResult = await executionOrchestrator.ExecuteStep(gaugeMethod, "hello", "async world");

Assert.That(executionResult.Failed, Is.False, executionResult.ErrorMessage);
StringAssert.Contains("hello, async world!", executionResult.Message.ToString());
}

[Test]
public void ShouldGetStacktraceForAggregateException()
public async Task ShouldGetStacktraceForAggregateException()
{
var reflectionWrapper = new ReflectionWrapper();
var activatorWrapper = new ActivatorWrapper();
Expand All @@ -140,7 +140,7 @@ public void ShouldGetStacktraceForAggregateException()
new StepExecutor(assemblyLoader, reflectionWrapper, classInstanceManager));

var gaugeMethod = assemblyLoader.GetStepRegistry().MethodFor("I throw an AggregateException");
var executionResult = executionOrchestrator.ExecuteStep(gaugeMethod);
var executionResult = await executionOrchestrator.ExecuteStep(gaugeMethod);

ClassicAssert.True(executionResult.Failed);
ClassicAssert.True(executionResult.StackTrace.Contains("First Exception"));
Expand All @@ -163,7 +163,7 @@ public void ShouldGetStepTextsForMethod()
}

[Test]
public void SuccessIsFalseOnSerializableExceptionThrown()
public async Task SuccessIsFalseOnSerializableExceptionThrown()
{
const string expectedMessage = "I am a custom serializable exception";
var reflectionWrapper = new ReflectionWrapper();
Expand All @@ -178,7 +178,7 @@ public void SuccessIsFalseOnSerializableExceptionThrown()
new StepExecutor(assemblyLoader, reflectionWrapper, classInstanceManager));
var gaugeMethod = assemblyLoader.GetStepRegistry().MethodFor("I throw a serializable exception");

var executionResult = executionOrchestrator.ExecuteStep(gaugeMethod);
var executionResult = await executionOrchestrator.ExecuteStep(gaugeMethod);

ClassicAssert.True(executionResult.Failed);
ClassicAssert.AreEqual(expectedMessage, executionResult.ErrorMessage);
Expand All @@ -187,7 +187,7 @@ public void SuccessIsFalseOnSerializableExceptionThrown()
}

[Test]
public void SuccessIsFalseOnUnserializableExceptionThrown()
public async Task SuccessIsFalseOnUnserializableExceptionThrown()
{
const string expectedMessage = "I am a custom exception";
var reflectionWrapper = new ReflectionWrapper();
Expand All @@ -202,7 +202,7 @@ public void SuccessIsFalseOnUnserializableExceptionThrown()
new StepExecutor(assemblyLoader, reflectionWrapper, classInstanceManager));

var gaugeMethod = assemblyLoader.GetStepRegistry().MethodFor("I throw an unserializable exception");
var executionResult = executionOrchestrator.ExecuteStep(gaugeMethod);
var executionResult = await executionOrchestrator.ExecuteStep(gaugeMethod);
ClassicAssert.True(executionResult.Failed);
ClassicAssert.AreEqual(expectedMessage, executionResult.ErrorMessage);
StringAssert.Contains("IntegrationTestSample.StepImplementation.ThrowUnserializableException",
Expand Down
5 changes: 3 additions & 2 deletions integration-test/ExternalReferenceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

using System;
using System.Threading;
using System.Threading.Tasks;
using Gauge.Dotnet.Models;
using Gauge.Dotnet.Processors;
using Gauge.Dotnet.Wrappers;
Expand Down Expand Up @@ -43,7 +44,7 @@ public void ShouldGetStepsFromReference(string referenceType, string stepText, s
[Test]
[TestCase("ProjectReference", "Take Screenshot in reference Project", "ReferenceProject-IDoNotExist.png")]
[TestCase("DllReference", "Take Screenshot in reference DLL", "ReferenceDll-IDoNotExist.png")]
public void ShouldRegisterScreenshotWriterFromReference(string referenceType, string stepText, string expected)
public async Task ShouldRegisterScreenshotWriterFromReference(string referenceType, string stepText, string expected)
{
Environment.SetEnvironmentVariable("GAUGE_PROJECT_ROOT", TestUtils.GetIntegrationTestSampleDirectory(referenceType));
var reflectionWrapper = new ReflectionWrapper();
Expand All @@ -66,7 +67,7 @@ public void ShouldRegisterScreenshotWriterFromReference(string referenceType, st
ActualStepText = stepText
};

var result = executeStepProcessor.Process(message);
var result = await executeStepProcessor.Process(message);
var protoExecutionResult = result.ExecutionResult;

ClassicAssert.IsNotNull(protoExecutionResult);
Expand Down
Loading

0 comments on commit 7259238

Please sign in to comment.