Skip to content

Commit

Permalink
Fix playground
Browse files Browse the repository at this point in the history
  • Loading branch information
Evangelink committed Aug 5, 2024
1 parent 982b20d commit b9b020b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 19 deletions.
6 changes: 6 additions & 0 deletions samples/Playground/Playground.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,10 @@
</None>
</ItemGroup>

<ItemGroup>
<ProjectCapability Include="DiagnoseCapabilities" />
<ProjectCapability Include="TestingPlatformServer" />
<ProjectCapability Include="TestContainer" />
</ItemGroup>

</Project>
16 changes: 10 additions & 6 deletions samples/Playground/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
using System.Reflection;

using Microsoft.Testing.Platform.Builder;
using Microsoft.Testing.Platform.ServerMode.IntegrationTests.Messages.V100;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using MSTest.Acceptance.IntegrationTests.Messages.V100;

namespace Playground;

public class Program
Expand All @@ -15,8 +18,12 @@ public static async Task<int> Main(string[] args)
// Opt-out telemetry
Environment.SetEnvironmentVariable("DOTNET_CLI_TELEMETRY_OPTOUT", "1");

ITestApplicationBuilder testApplicationBuilder = await TestApplication.CreateBuilderAsync(args);
testApplicationBuilder.AddMSTest(() => [Assembly.GetEntryAssembly()!]);
if (Environment.GetEnvironmentVariable("TESTSERVERMODE") != "1")
{
// To attach to the children
// Microsoft.Testing.TestInfrastructure.DebuggerUtility.AttachCurrentProcessToParentVSProcess();
ITestApplicationBuilder testApplicationBuilder = await TestApplication.CreateBuilderAsync(args);
testApplicationBuilder.AddMSTest(() => [Assembly.GetEntryAssembly()!]);

// Enable Trx
// testApplicationBuilder.AddTrxReportProvider();
Expand All @@ -40,10 +47,7 @@ public static async Task<int> Main(string[] args)
});
await discoveryResponse.WaitCompletionAsync();

ResponseListener runRequest = await client.RunTestsAsync(Guid.NewGuid(), testNodeUpdates.Select(x => x.Node).ToArray(), node =>
{
return Task.CompletedTask;
});
ResponseListener runRequest = await client.RunTestsAsync(Guid.NewGuid(), testNodeUpdates.Select(x => x.Node).ToArray(), node => Task.CompletedTask);
await runRequest.WaitCompletionAsync();

await client.ExitAsync();
Expand Down
21 changes: 8 additions & 13 deletions samples/Playground/ServerMode/TestingPlatformClientFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,10 @@ public static IProcessHandle Start(ProcessConfiguration config, bool cleanDefaul
ProcessHandleInfo processHandleInfo = new();
ProcessHandle processHandle = new(process, processHandleInfo);

process.Exited += (s, e) => config.OnExit?.Invoke(processHandle, process.ExitCode);
if (config.OnExit != null)
{
process.Exited += (s, e) => config.OnExit.Invoke(processHandle, process.ExitCode);
}

if (config.OnStandardOutput != null)
{
Expand Down Expand Up @@ -345,16 +348,12 @@ internal ProcessHandle(Process process, ProcessHandleInfo processHandleInfo)

public async Task<int> WaitForExitAsync()
{
if (_disposed)
if (!_disposed)
{
return _exitCode;
await _process.WaitForExitAsync();
}
#if NETCOREAPP
await _process.WaitForExitAsync();
#else
_process.WaitForExit();
#endif
return await Task.FromResult(_process.ExitCode);

return _exitCode;
}

public void WaitForExit() => _process.WaitForExit();
Expand Down Expand Up @@ -413,11 +412,7 @@ private static void KillSafe(Process process)
{
try
{
#if NETCOREAPP
process.Kill(true);
#else
process.Kill();
#endif
}
catch (InvalidOperationException)
{
Expand Down
12 changes: 12 additions & 0 deletions samples/Playground/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,20 @@ namespace Playground;
[TestClass]
public class TestClass
{
public TestContext TestContext { get; set; } = null!;

[TestMethod]
public void Test()
{
}

[TestMethod]
public void Test2()
{
}

[TestMethod]
public void Test3()
{
}
}

0 comments on commit b9b020b

Please sign in to comment.