Skip to content
Draft
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
11 changes: 8 additions & 3 deletions playground/TestPlatform.Playground/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
using System.Linq;
using System.Reflection;
using System.Threading;
#pragma warning disable IDE0005 // Using directive is unnecessary.
using System.Threading.Tasks;
#pragma warning restore IDE0005 // Using directive is unnecessary.

using Microsoft.TestPlatform.VsTestConsole.TranslationLayer;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
Expand All @@ -20,7 +23,7 @@ namespace TestPlatform.Playground;

internal class Program
{
static void Main()
static async Task Main()
{
// This project references TranslationLayer, vstest.console, TestHostProvider, testhost and MSTest1 projects, to make sure
// we build all the dependencies of that are used to run tests via VSTestConsoleWrapper. It then copies the components from
Expand Down Expand Up @@ -141,15 +144,17 @@ static void Main()
#pragma warning restore CS0618 // Type or member is obsolete
var discoveryHandler = new PlaygroundTestDiscoveryHandler(detailedOutput);
var sw = Stopwatch.StartNew();

// Discovery
r.DiscoverTests(sources, sourceSettings, options, sessionHandler.TestSessionInfo, discoveryHandler);
await r.DiscoverTestsAsync(sources, sourceSettings, options, sessionHandler.TestSessionInfo, discoveryHandler);
// r.DiscoverTests(sources, sourceSettings, options, sessionHandler.TestSessionInfo, discoveryHandler);
var discoveryDuration = sw.ElapsedMilliseconds;
Console.WriteLine($"Discovery done in {discoveryDuration} ms");
sw.Restart();
// Run with test cases and custom testhost launcher
//r.RunTestsWithCustomTestHost(discoveryHandler.TestCases, sourceSettings, options, sessionHandler.TestSessionInfo, new TestRunHandler(detailedOutput), new DebuggerTestHostLauncher());
//// Run with test cases and without custom testhost launcher
r.RunTests(discoveryHandler.TestCases, sourceSettings, options, sessionHandler.TestSessionInfo, new TestRunHandler(detailedOutput));
await r.RunTestsAsync(discoveryHandler.TestCases, sourceSettings, options, sessionHandler.TestSessionInfo, new TestRunHandler(detailedOutput));
//// Run with sources and custom testhost launcher and debugging
//r.RunTestsWithCustomTestHost(sources, sourceSettings, options, sessionHandler.TestSessionInfo, new TestRunHandler(detailedOutput), new DebuggerTestHostLauncher());
//// Run with sources
Expand Down
11 changes: 11 additions & 0 deletions playground/TestPlatform.Playground/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"profiles": {
"TestPlatform.Playground": {
"commandName": "Project",
"environmentVariables": {
"DOTNET_ThreadPool_ForceMinWorkerThreads": "1",
"DOTNET_ThreadPool_ForceMaxWorkerThreads": "1"
Comment on lines +6 to +7
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forces us to single threadpool thread to make sure we don't get blocked when running, and don't block threadpool threads.

}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<ProjectReference Include="$(RepoRoot)src\DataCollectors\DumpMinitool.arm64\DumpMinitool.arm64.csproj" SetTargetFramework="TargetFramework=$(NetFrameworkMinimum)" />

<!-- Event log collector only works on .NET Framework, and so we build it only for that. -->
<ProjectReference Include="$(RepoRoot)src\DataCollectors\Microsoft.TestPlatform.Extensions.EventLogCollector\Microsoft.TestPlatform.Extensions.EventLogCollector.csproj" SetTargetFramework="TargetFramework=$(NetFrameworkRunnerTargetFramework)" />
<ProjectReference Include="$(RepoRoot)src\DataCollectors\Microsoft.TestPlatform.Extensions.EventLogCollector\Microsoft.TestPlatform.Extensions.EventLogCollector.csproj" SetTargetFramework="TargetFramework=$(NetFrameworkRunnerTargetFramework)" />

<ProjectReference Include="$(RepoRoot)src\datacollector\datacollector.csproj" />
<ProjectReference Include="$(RepoRoot)src\Microsoft.TestPlatform.Extensions.BlameDataCollector\Microsoft.TestPlatform.Extensions.BlameDataCollector.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@ namespace Microsoft.TestPlatform.VsTestConsole.TranslationLayer.Interfaces;
/// </summary>
internal interface ITranslationLayerRequestSenderAsync : IDisposable
{

int StartServer();

/// <summary>
/// Asynchronous equivalent of <see cref="
/// ITranslationLayerRequestSender.InitializeCommunication"/>
/// and <see cref="
/// ITranslationLayerRequestSender.WaitForRequestHandlerConnection(
/// int)"/>.
/// </summary>
Task<int> InitializeCommunicationAsync(int clientConnectionTimeout);
Task InitializeCommunicationAsync(int clientConnectionTimeout);

/// <summary>
/// Asynchronous equivalent of ITranslationLayerRequestSender.DiscoverTests/>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,10 @@ public void StartProcess(ConsoleParameters consoleParameters)
_process!.EnableRaisingEvents = true;
_process.Exited += Process_Exited;

_process.OutputDataReceived += Process_OutputDataReceived;
_process.ErrorDataReceived += Process_ErrorDataReceived;
_process.BeginOutputReadLine();
_process.BeginErrorReadLine();
// _process.OutputDataReceived += Process_OutputDataReceived;
// _process.ErrorDataReceived += Process_ErrorDataReceived;
// _process.BeginOutputReadLine();
// _process.BeginErrorReadLine();
_processExitedEvent.Reset();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,36 +120,34 @@ public bool WaitForRequestHandlerConnection(int clientConnectionTimeout)
return waitSuccess && _handShakeSuccessful;
}

public int StartServer()
{
return _communicationManager.HostServer(new IPEndPoint(IPAddress.Loopback, 0)).Port;
}

/// <inheritdoc/>
public async Task<int> InitializeCommunicationAsync(int clientConnectionTimeout)
public async Task InitializeCommunicationAsync(int clientConnectionTimeout)
{
EqtTrace.Info($"VsTestConsoleRequestSender.InitializeCommunicationAsync: Started with client connection timeout {clientConnectionTimeout} milliseconds.");

_processExitCancellationTokenSource = new CancellationTokenSource();

_handShakeSuccessful = false;
_handShakeComplete.Reset();
int port = -1;

try
{
port = _communicationManager.HostServer(new IPEndPoint(IPAddress.Loopback, 0)).Port;
var timeoutSource = new CancellationTokenSource(clientConnectionTimeout);
await Task.Run(() =>
_communicationManager.AcceptClientAsync(), timeoutSource.Token).ConfigureAwait(false);
// todo: report standard error on timeout
await Task.WhenAny(_communicationManager.AcceptClientAsync(), Task.Delay(clientConnectionTimeout)).ConfigureAwait(false);

_handShakeSuccessful = await HandShakeWithVsTestConsoleAsync().ConfigureAwait(false);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is completely broken. We are waiting for console to connect here, but we did not return from this method, so the port was never given to the code that starts the console. So there is no process that would ever call us back.

_handShakeComplete.Set();
await HandShakeWithVsTestConsoleAsync().ConfigureAwait(false);

_handShakeSuccessful = true;
}
catch (Exception ex)
finally
{
EqtTrace.Error(
"VsTestConsoleRequestSender.InitializeCommunicationAsync: Error initializing communication with VstestConsole: {0}",
ex);
_handShakeComplete.Set();
}

EqtTrace.Info("VsTestConsoleRequestSender.InitializeCommunicationAsync: Ended.");

return _handShakeSuccessful ? port : -1;
}

/// <inheritdoc/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ public async Task StartSessionAsync()

var timeout = EnvironmentHelper.GetConnectionTimeout();
// Start communication
var port = await _requestSender.InitializeCommunicationAsync(timeout * 1000).ConfigureAwait(false);
var port = _requestSender.StartServer();

if (port > 0)
{
Expand All @@ -681,6 +681,8 @@ public async Task StartSessionAsync()
_requestSender.Close();
throw new TransationLayerException("Error hosting communication channel and connecting to console");
}

await _requestSender.InitializeCommunicationAsync(timeout * 1000).ConfigureAwait(false);
}

/// <inheritdoc/>
Expand Down
Loading