Skip to content

Commit 7e95180

Browse files
author
Paul van Brenk
committed
Telemetry for test adapter
1 parent 9dd8001 commit 7e95180

File tree

5 files changed

+59
-1
lines changed

5 files changed

+59
-1
lines changed

Nodejs/Product/TestAdapter/TestAdapter.csproj

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
<UpgradeBackupLocation>
88
</UpgradeBackupLocation>
99
<OldToolsVersion>4.0</OldToolsVersion>
10+
<NuGetPackageImportStamp>
11+
</NuGetPackageImportStamp>
1012
</PropertyGroup>
1113
<Import Project="..\ProjectBefore.settings" />
1214
<PropertyGroup>
@@ -40,6 +42,15 @@
4042
<Reference Include="envdte90, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
4143
<EmbedInteropTypes>False</EmbedInteropTypes>
4244
</Reference>
45+
<Reference Include="Microsoft.Diagnostics.Tracing.EventSource, Version=1.1.16.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
46+
<HintPath>..\..\packages\Microsoft.Diagnostics.Tracing.EventSource.Redist.1.1.16-beta\lib\net45\Microsoft.Diagnostics.Tracing.EventSource.dll</HintPath>
47+
</Reference>
48+
<Reference Include="Microsoft.VisualStudio.RemoteControl, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
49+
<HintPath>..\..\packages\Microsoft.VisualStudio.RemoteControl.14.0.262-masterA5CACE98\lib\net45\Microsoft.VisualStudio.RemoteControl.dll</HintPath>
50+
</Reference>
51+
<Reference Include="Microsoft.VisualStudio.Telemetry, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
52+
<HintPath>..\..\packages\Microsoft.VisualStudio.Telemetry.15.3.789-masterCC863119\lib\net45\Microsoft.VisualStudio.Telemetry.dll</HintPath>
53+
</Reference>
4354
<Reference Include="Microsoft.VisualStudio.TestPlatform.ObjectModel">
4455
<HintPath>$(DevEnvDir)CommonExtensions\Microsoft\TestWindow\Microsoft.VisualStudio.TestPlatform.ObjectModel.dll</HintPath>
4556
<Private>False</Private>
@@ -64,6 +75,9 @@
6475
<Reference Include="Microsoft.VisualStudio.ComponentModelHost, Version=$(VSTarget).0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
6576
<Reference Include="Microsoft.VisualStudio.CoreUtility" />
6677
<Reference Include="Microsoft.VisualStudio.OLE.Interop" />
78+
<Reference Include="Microsoft.VisualStudio.Utilities.Internal, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
79+
<HintPath>..\..\packages\Microsoft.VisualStudio.Utilities.Internal.14.0.72-masterF9EB1D39\lib\net45\Microsoft.VisualStudio.Utilities.Internal.dll</HintPath>
80+
</Reference>
6781
<Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
6882
<HintPath>..\..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
6983
</Reference>
@@ -147,8 +161,12 @@
147161
</Compile>
148162
</ItemGroup>
149163
<ItemGroup>
164+
<None Include="app.config" />
150165
<None Include="packages.config" />
151166
</ItemGroup>
167+
<ItemGroup>
168+
<Content Include="version.txt" />
169+
</ItemGroup>
152170
<Import Project="$(BuildRoot)\Nodejs\Product\Nodejs\SourceMapping\SourceMapping.proj" />
153171
<Import Project="..\ProjectAfter.settings" />
154172
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
@@ -157,5 +175,7 @@
157175
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
158176
</PropertyGroup>
159177
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
178+
<Error Condition="!Exists('..\..\packages\Microsoft.Diagnostics.Tracing.EventSource.Redist.1.1.16-beta\build\portable-net45+win8+wpa81\Microsoft.Diagnostics.Tracing.EventSource.Redist.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Microsoft.Diagnostics.Tracing.EventSource.Redist.1.1.16-beta\build\portable-net45+win8+wpa81\Microsoft.Diagnostics.Tracing.EventSource.Redist.targets'))" />
160179
</Target>
180+
<Import Project="..\..\packages\Microsoft.Diagnostics.Tracing.EventSource.Redist.1.1.16-beta\build\portable-net45+win8+wpa81\Microsoft.Diagnostics.Tracing.EventSource.Redist.targets" Condition="Exists('..\..\packages\Microsoft.Diagnostics.Tracing.EventSource.Redist.1.1.16-beta\build\portable-net45+win8+wpa81\Microsoft.Diagnostics.Tracing.EventSource.Redist.targets')" />
161181
</Project>

Nodejs/Product/TestAdapter/TestExecutor.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using System.Text;
1111
using System.Threading;
1212
using Microsoft.NodejsTools.TestAdapter.TestFrameworks;
13+
using Microsoft.VisualStudio.Telemetry;
1314
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
1415
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
1516
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
@@ -182,6 +183,16 @@ public void RunTests(IEnumerable<TestCase> tests, IRunContext runContext, IFrame
182183
}
183184
}
184185

186+
private void LogTelemetry(int testCount, bool isDebugging)
187+
{
188+
var userTask = new UserTaskEvent("VS/NodejsTools/UnitTestsExecuted", TelemetryResult.Success);
189+
userTask.Properties["VS.NodejsTools.TestCount"] = testCount;
190+
userTask.Properties["VS.NodejsTools.IsDebugging"] = isDebugging;
191+
192+
var defaultSession = TelemetryService.DefaultSession;
193+
defaultSession.PostEvent(userTask);
194+
}
195+
185196
private void RunTestCases(IEnumerable<TestCase> tests, IRunContext runContext, IFrameworkHandle frameworkHandle, NodejsProjectSettings settings)
186197
{
187198
// May be null, but this is handled by RunTestCase if it matters.
@@ -191,6 +202,7 @@ private void RunTestCases(IEnumerable<TestCase> tests, IRunContext runContext, I
191202
{
192203
return;
193204
}
205+
194206
using (var app = VisualStudioApp.FromEnvironmentVariable(NodejsConstants.NodeToolsProcessIdEnvironmentVariable))
195207
{
196208
var port = 0;
@@ -209,6 +221,14 @@ private void RunTestCases(IEnumerable<TestCase> tests, IRunContext runContext, I
209221
var testInfo = new NodejsTestInfo(tests.First().FullyQualifiedName);
210222
var workingDir = Path.GetDirectoryName(CommonUtils.GetAbsoluteFilePath(settings.WorkingDir, testInfo.ModulePath));
211223

224+
// we can only log telemetry when we're running in VS,
225+
// the required assemblies are not on disk, so we have to keep the call in a separate method
226+
// this way the .NET framework only loads the assemblies when we actually need them.
227+
if (app != null)
228+
{
229+
LogTelemetry(tests.Count(), runContext.IsBeingDebugged);
230+
}
231+
212232
foreach (var test in tests)
213233
{
214234
if (_cancelRequested.WaitOne(0))
@@ -365,7 +385,8 @@ private NodejsProjectSettings LoadProjectSettings(string projectFile)
365385
};
366386
}
367387

368-
private void RecordEnd(IFrameworkHandle frameworkHandle, TestCase test, TestResult result, ResultObject resultObject) {
388+
private void RecordEnd(IFrameworkHandle frameworkHandle, TestCase test, TestResult result, ResultObject resultObject)
389+
{
369390
String[] standardOutputLines = resultObject.stdout.Split('\n');
370391
String[] standardErrorLines = resultObject.stderr.Split('\n');
371392

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<runtime>
4+
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
5+
<dependentAssembly>
6+
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
7+
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
8+
</dependentAssembly>
9+
</assemblyBinding>
10+
</runtime>
11+
</configuration>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
33
<package id="MicroBuild.Core" version="0.2.0" targetFramework="net46" />
4+
<package id="Microsoft.Diagnostics.Tracing.EventSource.Redist" version="1.1.16-beta" targetFramework="net46" />
5+
<package id="Microsoft.VisualStudio.RemoteControl" version="14.0.262-masterA5CACE98" targetFramework="net46" />
6+
<package id="Microsoft.VisualStudio.Telemetry" version="15.3.789-masterCC863119" targetFramework="net46" />
7+
<package id="Microsoft.VisualStudio.Utilities.Internal" version="14.0.72-masterF9EB1D39" targetFramework="net46" />
48
<package id="Newtonsoft.Json" version="8.0.3" targetFramework="net46" />
59
</packages>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
AssemblyFileVersion=15.3-master
2+
AssemblyVersion=15.0

0 commit comments

Comments
 (0)