Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions samples/Playground/Playground.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<ProjectReference Include="$(RepoRoot)src\Analyzers\MSTest.Analyzers\MSTest.Analyzers.csproj" PrivateAssets="all" ReferenceOutputAssembly="false" OutputItemType="Analyzer" />
<PackageReference Include="StreamJsonRpc" />
<ProjectReference Include="$(RepoRoot)src\Platform\Microsoft.Testing.Extensions.Telemetry\Microsoft.Testing.Extensions.Telemetry.csproj" />
<ProjectReference Include="$(RepoRoot)src\Platform\Microsoft.Testing.Extensions.TrxReport\Microsoft.Testing.Extensions.TrxReport.csproj" />
<ProjectReference Include="$(RepoRoot)src\Platform\Microsoft.Testing.Extensions.CrashDump\Microsoft.Testing.Extensions.CrashDump.csproj" />
<ProjectReference Include="$(RepoRoot)src\Platform\Microsoft.Testing.Extensions.OpenTelemetry\Microsoft.Testing.Extensions.OpenTelemetry.csproj" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion samples/Playground/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static async Task<int> Main(string[] args)
// testApplicationBuilder.TestHostControllers.AddProcessLifetimeHandler(s => new OutOfProc(s.GetMessageBus()));

// Enable Trx
// testApplicationBuilder.AddTrxReportProvider();
testApplicationBuilder.AddTrxReportProvider();

// Enable Telemetry
// testApplicationBuilder.AddAppInsightsTelemetryProvider();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Microsoft.Testing.Platform.Extensions;
using Microsoft.Testing.Platform.Extensions.Messages;
using Microsoft.Testing.Platform.Extensions.OutputDevice;
using Microsoft.Testing.Platform.Extensions.TestHost;
using Microsoft.Testing.Platform.Helpers;
using Microsoft.Testing.Platform.Logging;
using Microsoft.Testing.Platform.OutputDevice.Terminal;
Expand All @@ -22,7 +21,6 @@ namespace Microsoft.Testing.Platform.OutputDevice;
internal sealed partial class TerminalOutputDevice : IHotReloadPlatformOutputDevice,
IDataConsumer,
IOutputDeviceDataProducer,
ITestSessionLifetimeHandler,
IDisposable,
IAsyncInitializableExtension
{
Expand Down Expand Up @@ -55,11 +53,11 @@ internal sealed partial class TerminalOutputDevice : IHotReloadPlatformOutputDev
private readonly string _assemblyName;

private TerminalTestReporter? _terminalTestReporter;
private bool _firstCallTo_OnSessionStartingAsync = true;
private bool _bannerDisplayed;
private bool _isListTests;
private bool _isServerMode;
private ILogger? _logger;
private TestProcessRole? _processRole;

public TerminalOutputDevice(
IConsole console,
Expand Down Expand Up @@ -325,36 +323,14 @@ private async Task DisplayAfterSessionEndRunInternalAsync()

using (await _asyncMonitor.LockAsync(TimeoutHelper.DefaultHangTimeSpanTimeout).ConfigureAwait(false))
{
if (!_firstCallTo_OnSessionStartingAsync)
if (_processRole == TestProcessRole.TestHost)
{
_terminalTestReporter.AssemblyRunCompleted();
_terminalTestReporter.TestExecutionCompleted(_clock.UtcNow);
}
}
}

public Task OnTestSessionFinishingAsync(ITestSessionContext testSessionContext) => Task.CompletedTask;

public Task OnTestSessionStartingAsync(ITestSessionContext testSessionContext)
{
CancellationToken cancellationToken = testSessionContext.CancellationToken;
cancellationToken.ThrowIfCancellationRequested();
if (_isServerMode)
{
return Task.CompletedTask;
}

// We implement IDataConsumerService and IOutputDisplayService.
// So the engine is calling us before as IDataConsumerService and after as IOutputDisplayService.
// The engine look for the ITestSessionLifetimeHandler in both case and call it.
if (_firstCallTo_OnSessionStartingAsync)
{
_firstCallTo_OnSessionStartingAsync = false;
}

return Task.CompletedTask;
}

/// <summary>
/// Displays provided data through IConsole, which is typically System.Console.
/// </summary>
Expand Down Expand Up @@ -416,9 +392,8 @@ public Task ConsumeAsync(IDataProducer dataProducer, IData value, CancellationTo

foreach (FileArtifactProperty artifact in testNodeStateChanged.TestNode.Properties.OfType<FileArtifactProperty>())
{
bool isOutOfProcessArtifact = _firstCallTo_OnSessionStartingAsync;
_terminalTestReporter.ArtifactAdded(
isOutOfProcessArtifact,
outOfProcess: _processRole != TestProcessRole.TestHost,
testNodeStateChanged.TestNode.DisplayName,
artifact.FileInfo.FullName);
}
Expand Down Expand Up @@ -532,19 +507,17 @@ public Task ConsumeAsync(IDataProducer dataProducer, IData value, CancellationTo

case SessionFileArtifact artifact:
{
bool isOutOfProcessArtifact = _firstCallTo_OnSessionStartingAsync;
_terminalTestReporter.ArtifactAdded(
isOutOfProcessArtifact,
outOfProcess: _processRole != TestProcessRole.TestHost,
testName: null,
artifact.FileInfo.FullName);
}

break;
case FileArtifact artifact:
{
bool isOutOfProcessArtifact = _firstCallTo_OnSessionStartingAsync;
_terminalTestReporter.ArtifactAdded(
isOutOfProcessArtifact,
outOfProcess: _processRole != TestProcessRole.TestHost,
testName: null,
artifact.FileInfo.FullName);
}
Expand All @@ -560,6 +533,7 @@ public void Dispose()

public async Task HandleProcessRoleAsync(TestProcessRole processRole, CancellationToken cancellationToken)
{
_processRole = processRole;
if (processRole == TestProcessRole.TestHost)
{
await _policiesService.RegisterOnMaxFailedTestsCallbackAsync(
Expand Down