Skip to content

Commit

Permalink
Remove ITestRunner.TestWorkerId
Browse files Browse the repository at this point in the history
  • Loading branch information
obligaron committed May 29, 2024
1 parent 61c7505 commit 027fad0
Show file tree
Hide file tree
Showing 22 changed files with 78 additions and 161 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# [vNext]

* Removed `ITestRunner.TestWorkerId` and related code (required to support scenario parallelization)

## Bug fixes:

* Fix: BeforeTestRun not run in .NET462 up to .NET481 in multitarget test project (#146)

# v2.0.0 - 2024-05-22

## Breaking changes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Public NotInheritable Class PROJECT_ROOT_NAMESPACE_MSTestAssemblyHooks
Public Shared Async Function AssemblyInitializeAsync(testContext As TestContext) As Task
Dim currentAssembly As Assembly = GetType(PROJECT_ROOT_NAMESPACE_MSTestAssemblyHooks).Assembly
Dim containerBuilder As New MsTestContainerBuilder(testContext)
Await Global.Reqnroll.TestRunnerManager.OnTestRunStartAsync(currentAssembly, Nothing, containerBuilder)
Await Global.Reqnroll.TestRunnerManager.OnTestRunStartAsync(currentAssembly, containerBuilder)
End Function

<AssemblyCleanup>
Expand Down

This file was deleted.

8 changes: 1 addition & 7 deletions Reqnroll.Generator/Generation/UnitTestFeatureGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,9 @@ private void SetupTestClassInitializeMethod(TestClassGenerationContext generatio
//testRunner = TestRunnerManager.GetTestRunnerForAssembly(null, [test_worker_id]);
var testRunnerField = _scenarioPartHelper.GetTestRunnerExpression();

var testRunnerParameters = new[]
{
new CodePrimitiveExpression(null),
_testGeneratorProvider.GetTestWorkerIdExpression()
};

var getTestRunnerExpression = new CodeMethodInvokeExpression(
new CodeTypeReferenceExpression(_codeDomHelper.GetGlobalizedTypeName(typeof(TestRunnerManager))),
nameof(TestRunnerManager.GetTestRunnerForAssembly), testRunnerParameters);
nameof(TestRunnerManager.GetTestRunnerForAssembly));

testClassInitializeMethod.Statements.Add(
new CodeAssignStatement(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,5 @@ public interface IUnitTestGeneratorProvider
void SetTestMethodAsRow(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, string scenarioTitle, string exampleSetName, string variantName, IEnumerable<KeyValuePair<string, string>> arguments);

void MarkCodeMethodInvokeExpressionAsAwait(CodeMethodInvokeExpression expression);

CodeExpression GetTestWorkerIdExpression();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,5 @@ public void MarkCodeMethodInvokeExpressionAsAwait(CodeMethodInvokeExpression exp
{
CodeDomHelper.MarkCodeMethodInvokeExpressionAsAwait(expression);
}

public CodeExpression GetTestWorkerIdExpression()
{
// System.Threading.Thread.CurrentThread.ManagedThreadId.ToString()
return new CodeMethodInvokeExpression(
new CodeVariableReferenceExpression("System.Threading.Thread.CurrentThread.ManagedThreadId"),
nameof(ToString)
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,5 @@ public void MarkCodeMethodInvokeExpressionAsAwait(CodeMethodInvokeExpression exp
{
CodeDomHelper.MarkCodeMethodInvokeExpressionAsAwait(expression);
}

public CodeExpression GetTestWorkerIdExpression()
=> new CodePropertyReferenceExpression(GetTestContextExpression(), TESTCONTEXT_WORKERID_PROPERTY);
}
}
22 changes: 0 additions & 22 deletions Reqnroll.Generator/UnitTestProvider/XUnit2TestGeneratorProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public class XUnit2TestGeneratorProvider : IUnitTestGeneratorProvider
protected internal const string IGNORE_TEST_CLASS = "IgnoreTestClass";
protected internal const string NONPARALLELIZABLE_COLLECTION_NAME = "ReqnrollNonParallelizableFeatures";
protected internal const string IASYNCLIFETIME_INTERFACE = "Xunit.IAsyncLifetime";
protected internal const string XUNITPARALLELWORKERTRACKER_INSTANCE = "Reqnroll.xUnit.ReqnrollPlugin.XUnitParallelWorkerTracker.Instance";

public XUnit2TestGeneratorProvider(CodeDomHelper codeDomHelper)
{
Expand Down Expand Up @@ -178,19 +177,6 @@ public virtual void FinalizeTestClass(TestClassGenerationContext generationConte
nameof(IObjectContainer.RegisterInstanceAs),
new CodeTypeReference(OUTPUT_INTERFACE)),
new CodeVariableReferenceExpression(OUTPUT_INTERFACE_FIELD_NAME)));

// Wrap FeatureTearDown:
// var testWorkerId = <testRunner>.TestWorkerId;
// <FeatureTearDown>
// XUnitParallelWorkerTracker.Instance.ReleaseWorker(testWorkerId);
generationContext.TestClassCleanupMethod.Statements.Insert(0,
new CodeVariableDeclarationStatement(typeof(string), "testWorkerId",
new CodePropertyReferenceExpression(new CodeVariableReferenceExpression(generationContext.TestRunnerField.Name), "TestWorkerId")));
generationContext.TestClassCleanupMethod.Statements.Add(
new CodeMethodInvokeExpression(
new CodeVariableReferenceExpression(GlobalNamespaceIfCSharp(XUNITPARALLELWORKERTRACKER_INSTANCE)),
"ReleaseWorker",
new CodeVariableReferenceExpression("testWorkerId")));
}

protected virtual void IgnoreFeature(TestClassGenerationContext generationContext)
Expand Down Expand Up @@ -414,14 +400,6 @@ public void MarkCodeMethodInvokeExpressionAsAwait(CodeMethodInvokeExpression exp
CodeDomHelper.MarkCodeMethodInvokeExpressionAsAwait(expression);
}

public CodeExpression GetTestWorkerIdExpression()
{
// XUnitParallelWorkerTracker.Instance.GetWorkerId()
return new CodeMethodInvokeExpression(
new CodeVariableReferenceExpression(GlobalNamespaceIfCSharp(XUNITPARALLELWORKERTRACKER_INSTANCE)),
"GetWorkerId");
}

private string GlobalNamespaceIfCSharp(string typeName)
{
return CodeDomHelper.TargetLanguage == CodeDomProviderLanguage.CSharp ? "global::" + typeName : typeName;
Expand Down
5 changes: 0 additions & 5 deletions Reqnroll/ISyncTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ namespace Reqnroll
{
public interface ISyncTestRunner
{
/// <summary>
/// The ID of the parallel test worker processing the current scenario. How the worker ID is obtained is dependent on the test execution framework.
/// </summary>
string TestWorkerId { get; }

FeatureContext FeatureContext { get; }
ScenarioContext ScenarioContext { get; }

Expand Down
6 changes: 0 additions & 6 deletions Reqnroll/ITestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,10 @@ namespace Reqnroll
{
public interface ITestRunner
{
/// <summary>
/// The ID of the parallel test worker processing the current scenario. How the worker ID is obtained is dependent on the test execution framework.
/// </summary>
string TestWorkerId { get; }
FeatureContext FeatureContext { get; }
ScenarioContext ScenarioContext { get; }
ITestThreadContext TestThreadContext { get; }

void InitializeTestRunner(string testWorkerId);

Task OnTestRunStartAsync();
Task OnTestRunEndAsync();

Expand Down
3 changes: 2 additions & 1 deletion Reqnroll/ITestRunnerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ public interface ITestRunnerManager
Assembly TestAssembly { get; }
Assembly[] BindingAssemblies { get; }
bool IsMultiThreaded { get; }
ITestRunner GetTestRunner(string workerId);
ITestRunner GetTestRunner();
void ReleaseTestThreadContext(ITestThreadContext testThreadContext);
void Initialize(Assembly testAssembly);
Task FireTestRunEndAsync();
Task FireTestRunStartAsync();
Expand Down
1 change: 0 additions & 1 deletion Reqnroll/Infrastructure/BlockingSyncTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ private void SyncWrapper(Func<Task> asyncCall)
asyncCall().GetAwaiter().GetResult();
}

public string TestWorkerId => _testRunner.TestWorkerId;
public FeatureContext FeatureContext => _testRunner.FeatureContext;
public ScenarioContext ScenarioContext => _testRunner.ScenarioContext;

Expand Down
1 change: 1 addition & 0 deletions Reqnroll/Infrastructure/TestExecutionEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ public virtual async Task OnFeatureEndAsync()
_testThreadExecutionEventPublisher.PublishEvent(new FeatureFinishedEvent(FeatureContext));

_contextManager.CleanupFeatureContext();
_testRunnerManager.ReleaseTestThreadContext(TestThreadContext);
}

public virtual void OnScenarioInitialize(ScenarioInfo scenarioInfo)
Expand Down
7 changes: 0 additions & 7 deletions Reqnroll/TestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ public class TestRunner : ITestRunner
{
private readonly ITestExecutionEngine _executionEngine;

public string TestWorkerId { get; private set; }

public TestRunner(ITestExecutionEngine executionEngine)
{
_executionEngine = executionEngine;
Expand All @@ -26,11 +24,6 @@ public async Task OnTestRunStartAsync()
await _executionEngine.OnTestRunStartAsync();
}

public void InitializeTestRunner(string testWorkerId)
{
TestWorkerId = testWorkerId;
}

public async Task OnFeatureStartAsync(FeatureInfo featureInfo)
{
await _executionEngine.OnFeatureStartAsync(featureInfo);
Expand Down
Loading

0 comments on commit 027fad0

Please sign in to comment.