Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make diagnostics client library tests not sleep #742

Merged
merged 4 commits into from
Feb 12, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void BasicEventPipeSessionTest()
public void EventPipeSessionStreamTest()
{
TestRunner runner = new TestRunner(CommonHelper.GetTraceePath(), output);
runner.Start(5000);
runner.Start(3000);
DiagnosticsClient client = new DiagnosticsClient(runner.Pid);
runner.PrintStatus();
output.WriteLine($"[{DateTime.Now.ToString()}] Trying to start an EventPipe session on process {runner.Pid}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public void MultiplePublishedProcessTest()
runner[i].Start();
pids[i] = runner[i].Pid;
}
System.Threading.Thread.Sleep(2000);
List<int> publishedProcesses = new List<int>(DiagnosticsClient.GetPublishedProcesses());
foreach (int p in publishedProcesses)
{
Expand Down
31 changes: 28 additions & 3 deletions src/tests/Microsoft.Diagnostics.NETCore.Client/TestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using Xunit;
using Xunit.Abstractions;

using Microsoft.Diagnostics.TestHelpers;

using Microsoft.Diagnostics.NETCore.Client;
using System.Threading.Tasks;
Copy link
Member

Choose a reason for hiding this comment

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

nit: Sort usings

using System.Runtime.InteropServices;
using System.IO;

namespace Microsoft.Diagnostics.NETCore.Client
{
Expand Down Expand Up @@ -57,9 +61,30 @@ public void Start(int timeoutInMS=0)
outputHelper.WriteLine($"Have total {testProcess.Modules.Count} modules loaded");
}

outputHelper.WriteLine($"[{DateTime.Now.ToString()}] Sleeping for {timeoutInMS} ms.");
Thread.Sleep(timeoutInMS);
outputHelper.WriteLine($"[{DateTime.Now.ToString()}] Done sleeping. Ready to test.");
// Block until we see the IPC channel created, or until timeout specified.
Task monitorSocketTask = Task.Run(() =>
{
while (true)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// On Windows, namedpipe connection will block until the named pipe is ready to connect so no need to block here
break;
}
else
{
// On Linux, we wait until the socket is created.
var matchingFiles = Directory.GetFiles(Path.GetTempPath(), $"dotnet-diagnostic-{testProcess.Id}-*-socket"); // Try best match.
if (matchingFiles.Length > 0)
{
break;
}
}
Thread.Sleep(100);
Copy link
Member

Choose a reason for hiding this comment

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

Task.Delay

}
});

monitorSocketTask.Wait(TimeSpan.FromMilliseconds(timeoutInMS));
Copy link
Member

Choose a reason for hiding this comment

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

Why synchronous?

}

public void Stop()
Expand Down