Skip to content

Commit

Permalink
Concept start end notify runner (#206)
Browse files Browse the repository at this point in the history
* Handle Runner concept start and end

Signed-off-by: Piotr Nestorow <piotr.nestorow@systemverification.com>

* Update ExecutableRunnerServiceHandler with concept start and end tasks

Signed-off-by: Piotr Nestorow <piotr.nestorow@systemverification.com>

* Updated StepFrom creating StepDetails

Signed-off-by: Piotr Nestorow <piotr.nestorow@systemverification.com>

* Concept related Step info update

Signed-off-by: Piotr Nestorow <piotr.nestorow@systemverification.com>

* Updated generating from proto files

Signed-off-by: Piotr Nestorow <piotr.nestorow@systemverification.com>

* Updated generating from proto files

Signed-off-by: Piotr Nestorow <piotr.nestorow@systemverification.com>

* Add support for Concept hooks

Signed-off-by: Piotr Nestorow <piotr.nestorow@systemverification.com>

* Added gauge-proto as a submodule

Signed-off-by: Piotr Nestorow <piotr.nestorow@systemverification.com>

* Fixed ShouldMapStepDetails test

Signed-off-by: Piotr Nestorow <piotr.nestorow@systemverification.com>

* Updated Gauge.CSharp.Lib version in _testdata projects

Signed-off-by: Piotr Nestorow <piotr.nestorow@systemverification.com>

* Added Concept hooks and updated Gauge.CSharp.Lib.dll in test projects

Signed-off-by: Piotr Nestorow <piotr.nestorow@systemverification.com>

---------

Signed-off-by: Piotr Nestorow <piotr.nestorow@systemverification.com>
  • Loading branch information
PiotrNestor authored Feb 20, 2024
1 parent 2523639 commit 5a9f766
Show file tree
Hide file tree
Showing 41 changed files with 35,980 additions and 16 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "gauge-proto"]
path = gauge-proto
url = https://github.com/getgauge/gauge-proto.git
2 changes: 1 addition & 1 deletion _testdata/ReferenceDllProject/ReferenceDll.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="4.19.4" />
<PackageReference Include="Gauge.CSharp.Lib" Version="0.7.6" />
<PackageReference Include="Gauge.CSharp.Lib" Version="0.10.0" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion _testdata/ReferenceProject/ReferenceProject.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="4.19.4" />
<PackageReference Include="Gauge.CSharp.Lib" Version="0.7.6" />
<PackageReference Include="Gauge.CSharp.Lib" Version="0.10.0" />
</ItemGroup>

</Project>
10 changes: 10 additions & 0 deletions _testdata/Sample/ExecutionHooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ public void AfterStep()
{
}

[BeforeConcept]
public void BeforeConcept()
{
}

[AfterConcept]
public void AfterConcept()
{
}

[BeforeSpec]
public void BeforeSpec()
{
Expand Down
2 changes: 1 addition & 1 deletion _testdata/Sample/IntegrationTestSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Gauge.CSharp.Lib" Version="0.7.6" />
<PackageReference Include="Gauge.CSharp.Lib" Version="0.10.0" />
</ItemGroup>
</Project>
Binary file modified _testdata/Sample/gauge_bin/Gauge.CSharp.Lib.dll
Binary file not shown.
10 changes: 10 additions & 0 deletions _testdata/SampleDllReference/ExecutionHooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ public void AfterStep()
{
}

[BeforeConcept]
public void BeforeConcept()
{
}

[AfterConcept]
public void AfterConcept()
{
}

[BeforeSpec]
public void BeforeSpec()
{
Expand Down
2 changes: 1 addition & 1 deletion _testdata/SampleDllReference/IntegrationTestSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Gauge.CSharp.Lib" Version="0.7.6" />
<PackageReference Include="Gauge.CSharp.Lib" Version="0.10.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Binary file modified _testdata/SampleDllReference/gauge_bin/Gauge.CSharp.Lib.dll
Binary file not shown.
10 changes: 10 additions & 0 deletions _testdata/SampleProjectReference/ExecutionHooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ public void AfterStep()
{
}

[BeforeConcept]
public void BeforeConcept()
{
}

[AfterConcept]
public void AfterConcept()
{
}

[BeforeSpec]
public void BeforeSpec()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Gauge.CSharp.Lib" Version="0.7.6" />
<PackageReference Include="Gauge.CSharp.Lib" Version="0.10.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Binary file not shown.
1 change: 1 addition & 0 deletions gauge-proto
Submodule gauge-proto added at 9e50db
32 changes: 32 additions & 0 deletions gen-proto.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# ----------------------------------------------------------------
# Copyright (c) ThoughtWorks, Inc.
# Licensed under the Apache License, Version 2.0
# See LICENSE.txt in the project root for license information.
# ----------------------------------------------------------------

dotnet restore

$grpc_tools_version = "2.61.0"
$grpc_tools = Join-Path $HOME ".nuget\packages\grpc.tools\$grpc_tools_version\tools"

$protoc = $null
$grpc_csharp = $null

if ($env:PROCESSOR_ARCHITECTURE -match 64){
$protoc = Resolve-Path $grpc_tools\windows_x64\protoc.exe
$grpc_csharp = Resolve-Path $grpc_tools\windows_x64\grpc_csharp_plugin.exe
}
else {
$protoc = Resolve-Path $grpc_tools\windows_x86\protoc.exe
$grpc_csharp = Resolve-Path $grpc_tools\windows_x86\grpc_csharp_plugin.exe
}

Write-Host "Generating Proto Classes.."


gci ".\gauge-proto" -Filter "*.proto" | %{
Write-Host "Generating classes for $_"
&$protoc @('-I.\gauge-proto', '--csharp_out=.\src\Gauge.CSharp.Core','--grpc_out=.\src\Gauge.CSharp.Core',"--plugin=protoc-gen-grpc=$grpc_csharp", ".\gauge-proto\$_")
}

Write-Host "Done!"
68 changes: 68 additions & 0 deletions genproto.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#! /bin/bash

set_os_architecture() {
echo "Detecting architecture"
local _ostype="$(uname -s)"
local _cputype="$(uname -m)"

echo "uname -s reports: $_ostype"
echo "uname -m reports: $_cputype"

if [ "$_ostype" = Darwin -a "$_cputype" = i386 ]; then
# Darwin `uname -s` lies
if sysctl hw.optional.x86_64 | grep -q ': 1'; then
local _cputype=x86_64
fi
fi

case "$_ostype" in

Linux)
local _ostype=linux
;;
Darwin)
local _ostype=macosx
;;
*)
#err "Unknown OS type: $_ostype"
;;
esac

case "$_cputype" in

i386 | i486 | i686 | i786 | x86)
local _cputype=x86
;;
x86_64 | x86-64 | x64 | amd64)
local _cputype=x64
;;
*)
#err "Unknown CPU type: $_cputype"
;;
esac

echo "OS is $_ostype"
echo "Architecture is $_cputype"
ARCH="$_cputype"
OS="$_ostype"
}


set_os_architecture

dotnet restore

grpc_tools_version="2.61.0"
protoc="$HOME"/.nuget/packages/build/grpc.tools/"grpc_tools_version"/tools/"$OS"_"$ARCH"/protoc
grpc_csharp="$HOME"/.nuget/packages/build/grpc.tools/"grpc_tools_version"/tools/"$OS"_"$ARCH"/grpc_csharp_plugin

chmod +x $protoc
chmod +x $grpc_csharp

echo "Generating Proto Classes.."

for i in `ls ./gauge-proto/*.proto`; do
$protoc -I./gauge-proto --csharp_out=./src/Gauge.CSharp.Core --grpc_out=./src/Gauge.CSharp.Core --plugin=protoc-gen-grpc=$grpc_csharp $i
done

echo "Done"
19 changes: 17 additions & 2 deletions src/ExecutableRunnerServiceHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ internal class ExecutableRunnerServiceHandler : AuthoringRunnerServiceHandler
private ScenarioExecutionEndingProcessor scenarioExecutionEndingProcessor;
private StepExecutionStartingProcessor stepExecutionStartingProcessor;
private StepExecutionEndingProcessor stepExecutionEndingProcessor;
private ConceptExecutionStartingProcessor conceptExecutionStartingProcessor;
private ConceptExecutionEndingProcessor conceptExecutionEndingProcessor;
private ExecuteStepProcessor executeStepProcessor;
private ScenarioDataStoreInitProcessor scenarioDataStoreInitProcessor;
private SpecDataStoreInitProcessor specDataStoreInitProcessor;
private SuiteDataStoreInitProcessor suiteDataStoreInitProcessor;
public ExecutableRunnerServiceHandler(IActivatorWrapper activationWrapper, IReflectionWrapper reflectionWrapper,
public ExecutableRunnerServiceHandler(IActivatorWrapper activationWrapper, IReflectionWrapper reflectionWrapper,
IAssemblyLoader assemblyLoader, IStaticLoader loader, ExecutorPool pool, IHostApplicationLifetime lifetime)
: base(loader, pool, lifetime)
{
Expand All @@ -49,7 +51,7 @@ public override Task<ExecutionStatusResponse> InitializeSuiteDataStore(SuiteData
return _pool.Execute(getStream(request.Stream), () => this.suiteDataStoreInitProcessor.Process());
}

public override Task<ExecutionStatusResponse> ExecuteStep(ExecuteStepRequest request, ServerCallContext context)
public override Task<ExecutionStatusResponse> ExecuteStep(ExecuteStepRequest request, ServerCallContext context)
{
return _pool.Execute(getStream(request.Stream), () => this.executeStepProcessor.Process(request));
}
Expand Down Expand Up @@ -113,6 +115,17 @@ public override Task<ExecutionStatusResponse> StartStepExecution(StepExecutionSt
return _pool.Execute(getStream(request.Stream), () => this.stepExecutionStartingProcessor.Process(request));
}

public override Task<Empty> NotifyConceptExecutionStarting(ConceptExecutionStartingRequest request, ServerCallContext context)
{
return _pool.Execute(getStream(request.Stream), () => this.conceptExecutionStartingProcessor.Process(request));
}

public override Task<Empty> NotifyConceptExecutionEnding(ConceptExecutionEndingRequest request, ServerCallContext context)
{
return _pool.Execute(getStream(request.Stream), () => this.conceptExecutionEndingProcessor.Process(request));
}


private void InitializeExecutionMessageHandlers()
{
var tableFormatter = new TableFormatter(this._assemblyLoader, this._activatorWrapper);
Expand All @@ -134,6 +147,8 @@ private void InitializeExecutionMessageHandlers()
this.scenarioExecutionEndingProcessor = new ScenarioExecutionEndingProcessor(executionOrchestrator);
this.stepExecutionStartingProcessor = new StepExecutionStartingProcessor(executionOrchestrator);
this.stepExecutionEndingProcessor = new StepExecutionEndingProcessor(executionOrchestrator);
this.conceptExecutionStartingProcessor = new ConceptExecutionStartingProcessor(executionOrchestrator);
this.conceptExecutionEndingProcessor = new ConceptExecutionEndingProcessor(executionOrchestrator);
this.executeStepProcessor = new ExecuteStepProcessor(_stepRegistry, executionOrchestrator, tableFormatter);
this.scenarioDataStoreInitProcessor = new ScenarioDataStoreInitProcessor(this._assemblyLoader);
this.specDataStoreInitProcessor = new SpecDataStoreInitProcessor(this._assemblyLoader);
Expand Down
5 changes: 4 additions & 1 deletion src/ExecutionInfoMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ private dynamic StepFrom(StepInfo currentStep)
if (currentStep == null || currentStep.Step == null)
return activatorWrapper.CreateInstance(executionContextStepType);

return activatorWrapper.CreateInstance(executionContextStepType, currentStep.Step.ActualStepText, currentStep.IsFailed);
return activatorWrapper.CreateInstance(
executionContextStepType,
currentStep.Step.ActualStepText, currentStep.IsFailed,
currentStep.StackTrace, currentStep.ErrorMessage);
}
}
}
50 changes: 50 additions & 0 deletions src/Gauge.CSharp.Core/AbstractGaugeConnection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*----------------------------------------------------------------
* Copyright (c) ThoughtWorks, Inc.
* Licensed under the Apache License, Version 2.0
* See LICENSE.txt in the project root for license information.
*----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using Google.Protobuf;

namespace Gauge.CSharp.Core
{
public abstract class AbstractGaugeConnection : IDisposable
{
protected readonly ITcpClientWrapper TcpClientWrapper;

protected AbstractGaugeConnection(ITcpClientWrapper tcpClientWrapper)
{
TcpClientWrapper = tcpClientWrapper;
}

public bool Connected => TcpClientWrapper.Connected;

public void Dispose()
{
TcpClientWrapper.Close();
}

public void WriteMessage(IMessage request)
{
var bytes = request.ToByteArray();
var cos = new CodedOutputStream(TcpClientWrapper.GetStream());
cos.WriteUInt64((ulong) bytes.Length);
cos.Flush();
TcpClientWrapper.GetStream().Write(bytes, 0, bytes.Length);
TcpClientWrapper.GetStream().Flush();
}

public IEnumerable<byte> ReadBytes()
{
var networkStream = TcpClientWrapper.GetStream();
var codedInputStream = new CodedInputStream(networkStream);
return codedInputStream.ReadBytes();
}

protected static long GenerateMessageId()
{
return DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
}
}
}
Loading

0 comments on commit 5a9f766

Please sign in to comment.