-
Notifications
You must be signed in to change notification settings - Fork 292
Add telemetry collection for MSTest usage analytics #7570
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
base: main
Are you sure you want to change the base?
Changes from all commits
06ad3e1
b609215
3e6f8b5
6265e4f
f1c1fa5
cbf9140
2a26a81
6259d0e
07a82f9
4820a42
ecb2b57
298cf4f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,9 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter; | |
| internal sealed class MSTestExecutor : ITestExecutor | ||
| { | ||
| private readonly CancellationToken _cancellationToken; | ||
| #if !WINDOWS_UWP && !WIN_UI | ||
| private readonly Func<string, IDictionary<string, object>, Task>? _telemetrySender; | ||
| #endif | ||
|
|
||
| /// <summary> | ||
| /// Token for canceling the test run. | ||
|
|
@@ -35,10 +38,15 @@ public MSTestExecutor() | |
| _cancellationToken = CancellationToken.None; | ||
| } | ||
|
|
||
| internal MSTestExecutor(CancellationToken cancellationToken) | ||
| internal MSTestExecutor(CancellationToken cancellationToken, Func<string, IDictionary<string, object>, Task>? telemetrySender = null) | ||
| { | ||
| TestExecutionManager = new TestExecutionManager(); | ||
| _cancellationToken = cancellationToken; | ||
| #if !WINDOWS_UWP && !WIN_UI | ||
| _telemetrySender = telemetrySender; | ||
| #else | ||
| _ = telemetrySender; | ||
| #endif | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
@@ -115,12 +123,27 @@ internal async Task RunTestsAsync(IEnumerable<TestCase>? tests, IRunContext? run | |
|
|
||
| Ensure.NotEmpty(tests); | ||
|
|
||
| // Initialize telemetry collection if not already set | ||
| #if !WINDOWS_UWP && !WIN_UI | ||
| if (!MSTestTelemetryDataCollector.IsTelemetryOptedOut()) | ||
| { | ||
| _ = MSTestTelemetryDataCollector.EnsureInitialized(); | ||
| } | ||
| #endif | ||
|
|
||
|
Evangelink marked this conversation as resolved.
|
||
| if (!MSTestDiscovererHelpers.InitializeDiscovery(from test in tests select test.Source, runContext, frameworkHandle, configuration, new TestSourceHandler())) | ||
| { | ||
| return; | ||
| } | ||
|
Comment on lines
+126
to
137
|
||
|
|
||
| await RunTestsFromRightContextAsync(frameworkHandle, async testRunToken => await TestExecutionManager.RunTestsAsync(tests, runContext, frameworkHandle, testRunToken).ConfigureAwait(false)).ConfigureAwait(false); | ||
| try | ||
| { | ||
| await RunTestsFromRightContextAsync(frameworkHandle, async testRunToken => await TestExecutionManager.RunTestsAsync(tests, runContext, frameworkHandle, testRunToken).ConfigureAwait(false)).ConfigureAwait(false); | ||
| } | ||
| finally | ||
| { | ||
| await SendTelemetryAsync().ConfigureAwait(false); | ||
| } | ||
| } | ||
|
|
||
| internal async Task RunTestsAsync(IEnumerable<string>? sources, IRunContext? runContext, IFrameworkHandle? frameworkHandle, IConfiguration? configuration, bool isMTP) | ||
|
|
@@ -143,14 +166,29 @@ internal async Task RunTestsAsync(IEnumerable<string>? sources, IRunContext? run | |
|
|
||
| Ensure.NotEmpty(sources); | ||
|
|
||
| // Initialize telemetry collection if not already set | ||
| #if !WINDOWS_UWP && !WIN_UI | ||
| if (!MSTestTelemetryDataCollector.IsTelemetryOptedOut()) | ||
| { | ||
| _ = MSTestTelemetryDataCollector.EnsureInitialized(); | ||
| } | ||
| #endif | ||
|
|
||
| TestSourceHandler testSourceHandler = new(); | ||
| if (!MSTestDiscovererHelpers.InitializeDiscovery(sources, runContext, frameworkHandle, configuration, testSourceHandler)) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| sources = testSourceHandler.GetTestSources(sources); | ||
| await RunTestsFromRightContextAsync(frameworkHandle, async testRunToken => await TestExecutionManager.RunTestsAsync(sources, runContext, frameworkHandle, testSourceHandler, isMTP, testRunToken).ConfigureAwait(false)).ConfigureAwait(false); | ||
| try | ||
| { | ||
| await RunTestsFromRightContextAsync(frameworkHandle, async testRunToken => await TestExecutionManager.RunTestsAsync(sources, runContext, frameworkHandle, testSourceHandler, isMTP, testRunToken).ConfigureAwait(false)).ConfigureAwait(false); | ||
| } | ||
| finally | ||
| { | ||
| await SendTelemetryAsync().ConfigureAwait(false); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
@@ -159,6 +197,14 @@ internal async Task RunTestsAsync(IEnumerable<string>? sources, IRunContext? run | |
| public void Cancel() | ||
| => _testRunCancellationToken?.Cancel(); | ||
|
|
||
| #if !WINDOWS_UWP && !WIN_UI | ||
| private Task SendTelemetryAsync() | ||
| => MSTestTelemetryDataCollector.SendTelemetryAndResetAsync(_telemetrySender); | ||
| #else | ||
| private static Task SendTelemetryAsync() | ||
| => Task.CompletedTask; | ||
| #endif | ||
|
|
||
| private async Task RunTestsFromRightContextAsync(IFrameworkHandle frameworkHandle, Func<TestRunCancellationToken, Task> runTestsAction) | ||
| { | ||
| ApartmentState? requestedApartmentState = MSTestSettings.RunConfigurationSettings.ExecutionApartmentState; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.