提交 5c4be514 编写于 作者: R Ravi Chande 提交者: GitHub

Merge pull request #20956 from rchande/integrationTelemetry

In integration tests, verify that we send telemetry

Fixes https://github.com/dotnet/roslyn/issues/20105
......@@ -74,7 +74,9 @@ void M()
[Fact, Trait(Traits.Feature, Traits.Features.FindReferences)]
public void FindReferencesToLocals()
{
SetUpEditor(@"
using (var telemetry = VisualStudio.EnableTestTelemetryChannel())
{
SetUpEditor(@"
class Program
{
static void Main()
......@@ -85,18 +87,18 @@ static void Main()
}
");
VisualStudio.Editor.SendKeys(Shift(VirtualKey.F12));
VisualStudio.Editor.SendKeys(Shift(VirtualKey.F12));
const string localReferencesCaption = "'local' references";
var results = VisualStudio.FindReferencesWindow.GetContents(localReferencesCaption);
const string localReferencesCaption = "'local' references";
var results = VisualStudio.FindReferencesWindow.GetContents(localReferencesCaption);
var activeWindowCaption = VisualStudio.Shell.GetActiveWindowCaption();
Assert.Equal(expected: localReferencesCaption, actual: activeWindowCaption);
var activeWindowCaption = VisualStudio.Shell.GetActiveWindowCaption();
Assert.Equal(expected: localReferencesCaption, actual: activeWindowCaption);
Assert.Collection(
results,
new Action<Reference>[]
{
Assert.Collection(
results,
new Action<Reference>[]
{
reference =>
{
Assert.Equal(expected: "int local = 1;", actual: reference.Code);
......@@ -109,7 +111,10 @@ static void Main()
Assert.Equal(expected: 6, actual: reference.Line);
Assert.Equal(expected: 26, actual: reference.Column);
}
});
});
telemetry.VerifyFired("vs/platform/findallreferences/search", "vs/ide/vbcs/commandhandler/findallreference");
}
}
[Fact, Trait(Traits.Feature, Traits.Features.FindReferences)]
......
......@@ -22,7 +22,9 @@ public CSharpFormatting(VisualStudioInstanceFactory instanceFactory)
[Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
public void AlignOpenBraceWithMethodDeclaration()
{
SetUpEditor(@"
using (var telemetry = VisualStudio.EnableTestTelemetryChannel())
{
SetUpEditor(@"
$$class C
{
void Main()
......@@ -30,14 +32,16 @@ void Main()
}
}");
VisualStudio.Editor.FormatDocument();
VisualStudio.Editor.Verify.TextContains(@"
VisualStudio.Editor.FormatDocument();
VisualStudio.Editor.Verify.TextContains(@"
class C
{
void Main()
{
}
}");
telemetry.VerifyFired("vs/ide/vbcs/commandhandler/formatcommand");
}
}
[Fact, Trait(Traits.Feature, Traits.Features.Formatting)]
......
......@@ -23,31 +23,36 @@ public CSharpNavigateTo(VisualStudioInstanceFactory instanceFactory)
[Fact(Skip = "https://github.com/dotnet/roslyn/issues/19530"), Trait(Traits.Feature, Traits.Features.NavigateTo)]
public void NavigateTo()
{
var project = new ProjectUtils.Project(ProjectName);
VisualStudio.SolutionExplorer.AddFile(project, "test1.cs", open: false, contents: @"
using (var telemetry = VisualStudio.EnableTestTelemetryChannel())
{
var project = new ProjectUtils.Project(ProjectName);
VisualStudio.SolutionExplorer.AddFile(project, "test1.cs", open: false, contents: @"
class FirstClass
{
void FirstMethod() { }
}");
VisualStudio.SolutionExplorer.AddFile(project, "test2.cs", open: true, contents: @"
VisualStudio.SolutionExplorer.AddFile(project, "test2.cs", open: true, contents: @"
");
VisualStudio.Editor.InvokeNavigateTo("FirstMethod");
VisualStudio.Editor.NavigateToSendKeys("{ENTER}");
VisualStudio.Editor.WaitForActiveView("test1.cs");
Assert.Equal("FirstMethod", VisualStudio.Editor.GetSelectedText());
// Add a VB project and verify that VB files are found when searching from C#
var vbProject = new ProjectUtils.Project("VBProject");
VisualStudio.SolutionExplorer.AddProject(vbProject, WellKnownProjectTemplates.ClassLibrary, LanguageNames.VisualBasic);
VisualStudio.SolutionExplorer.AddFile(vbProject, "vbfile.vb", open: true);
VisualStudio.Editor.InvokeNavigateTo("FirstClass");
VisualStudio.Editor.NavigateToSendKeys("{ENTER}");
VisualStudio.Editor.WaitForActiveView("test1.cs");
Assert.Equal("FirstClass", VisualStudio.Editor.GetSelectedText());
VisualStudio.Editor.InvokeNavigateTo("FirstMethod");
VisualStudio.Editor.NavigateToSendKeys("{ENTER}");
VisualStudio.Editor.WaitForActiveView("test1.cs");
Assert.Equal("FirstMethod", VisualStudio.Editor.GetSelectedText());
// Add a VB project and verify that VB files are found when searching from C#
var vbProject = new ProjectUtils.Project("VBProject");
VisualStudio.SolutionExplorer.AddProject(vbProject, WellKnownProjectTemplates.ClassLibrary, LanguageNames.VisualBasic);
VisualStudio.SolutionExplorer.AddFile(vbProject, "vbfile.vb", open: true);
VisualStudio.Editor.InvokeNavigateTo("FirstClass");
VisualStudio.Editor.NavigateToSendKeys("{ENTER}");
VisualStudio.Editor.WaitForActiveView("test1.cs");
Assert.Equal("FirstClass", VisualStudio.Editor.GetSelectedText());
telemetry.VerifyFired("vs/ide/vbcs/navigateto/search", "vs/platform/goto/launch");
}
}
}
}
......@@ -47,15 +47,17 @@ static void TestMethod(int y)
}
}";
SetUpEditor(markup);
InlineRenameDialog.Invoke();
using (var telemetry = VisualStudio.EnableTestTelemetryChannel())
{
SetUpEditor(markup);
InlineRenameDialog.Invoke();
MarkupTestFile.GetSpans(markup, out var _, out ImmutableArray<TextSpan> renameSpans);
var tags = VisualStudio.Editor.GetTagSpans(InlineRenameDialog.ValidRenameTag);
AssertEx.SetEqual(renameSpans, tags);
MarkupTestFile.GetSpans(markup, out var _, out ImmutableArray<TextSpan> renameSpans);
var tags = VisualStudio.Editor.GetTagSpans(InlineRenameDialog.ValidRenameTag);
AssertEx.SetEqual(renameSpans, tags);
VisualStudio.Editor.SendKeys(VirtualKey.Y, VirtualKey.Enter);
VisualStudio.Editor.Verify.TextContains(@"
VisualStudio.Editor.SendKeys(VirtualKey.Y, VirtualKey.Enter);
VisualStudio.Editor.Verify.TextContains(@"
using System;
using System.Collections.Generic;
using System.Linq;
......@@ -74,6 +76,8 @@ static void TestMethod(int y)
}
}");
telemetry.VerifyFired("vs/ide/vbcs/rename/inlinesession/session", "vs/ide/vbcs/rename/commitcore");
}
}
[Fact, Trait(Traits.Feature, Traits.Features.Rename)]
......
......@@ -66,5 +66,8 @@ protected static void WaitForApplicationIdle()
protected static void WaitForSystemIdle()
=> CurrentApplicationDispatcher.Invoke(() => { }, DispatcherPriority.SystemIdle);
// Ensure InProcComponents live forever
public override object InitializeLifetimeService() => null;
}
}
......@@ -8,7 +8,7 @@
namespace Microsoft.VisualStudio.IntegrationTest.Utilities.InProcess
{
internal class VisualStudio_InProc : InProcComponent
internal partial class VisualStudio_InProc : InProcComponent
{
private VisualStudio_InProc() { }
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.Telemetry;
namespace Microsoft.VisualStudio.IntegrationTest.Utilities.InProcess
{
internal partial class VisualStudio_InProc : InProcComponent
{
public void EnableTestTelemetryChannel()
{
InvokeOnUIThread(() =>
{
TelemetryService.DetachTestChannel(LoggerTestChannel.Instance);
LoggerTestChannel.Instance.Clear();
TelemetryService.AttachTestChannel(LoggerTestChannel.Instance);
});
}
public void DisableTestTelemetryChannel()
{
InvokeOnUIThread(() =>
{
TelemetryService.DetachTestChannel(LoggerTestChannel.Instance);
LoggerTestChannel.Instance.Clear();
});
}
public void WaitForTelemetryEvents(string[] names)
=> LoggerTestChannel.Instance.WaitForEvents(names);
private sealed class LoggerTestChannel : ITelemetryTestChannel
{
public static readonly LoggerTestChannel Instance = new LoggerTestChannel();
private ConcurrentBag<TelemetryEvent> eventsQueue =
new ConcurrentBag<TelemetryEvent>();
/// <summary>
/// Waits for one or more events with the specified names
/// </summary>
/// <param name="events"></param>
public void WaitForEvents(string[] events)
{
var set = new HashSet<string>(events);
while (true)
{
if (eventsQueue.TryTake(out var result))
{
set.Remove(result.Name);
if (set.Count == 0)
{
return;
}
}
else
{
System.Threading.Thread.Sleep(1000);
}
}
}
/// <summary>
/// Clear current queue.
/// </summary>
public void Clear()
{
this.eventsQueue = new ConcurrentBag<TelemetryEvent>();
}
/// <summary>
/// Process incoming events.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void ITelemetryTestChannel.OnPostEvent(object sender, TelemetryTestChannelEventArgs e)
{
this.eventsQueue.Add(e.Event);
}
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.ExceptionServices;
using System.Runtime.InteropServices;
using System.Runtime.Remoting.Channels;
......@@ -252,5 +254,39 @@ private static T RetryRpcCall<T>(Func<T> action)
return result;
}
public TelemetryVerifier EnableTestTelemetryChannel()
{
_inProc.EnableTestTelemetryChannel();
return new TelemetryVerifier(this);
}
private void DisableTestTelemetryChannel()
=> _inProc.DisableTestTelemetryChannel();
private void WaitForTelemetryEvents(string[] names)
=> _inProc.WaitForTelemetryEvents(names);
public class TelemetryVerifier : IDisposable
{
internal VisualStudioInstance _instance;
public TelemetryVerifier(VisualStudioInstance instance)
{
_instance = instance;
}
public void Dispose() => _instance.DisableTestTelemetryChannel();
/// <summary>
/// Asserts that a telemetry event of the given name was fired. Does not
/// do any additional validation (of performance numbers, etc).
/// </summary>
/// <param name="expectedEventNames"></param>
public void VerifyFired(params string[] expectedEventNames)
{
_instance.WaitForTelemetryEvents(expectedEventNames);
}
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册