未验证 提交 914e8b03 编写于 作者: S Sam Harwell 提交者: GitHub

Merge pull request #25909 from sharwell/light-bulb-timeout

Apply a hang mitigating timeout to WaitForLightBulbSessionAsync
......@@ -19,11 +19,6 @@ namespace Roslyn.VisualStudio.IntegrationTests
[CaptureTestName]
public abstract class AbstractIntegrationTest : IAsyncLifetime, IDisposable
{
/// <summary>
/// A long timeout used to avoid hangs in tests, where a test failure manifests as an operation never occurring.
/// </summary>
protected static readonly TimeSpan HangMitigatingTimeout = TimeSpan.FromMinutes(1);
protected readonly string ProjectName = "TestProj";
protected readonly string SolutionName = "TestSolution";
......
......@@ -40,11 +40,11 @@ public void EncapsulateThroughCommand()
var encapsulateField = VisualStudio.EncapsulateField;
var dialog = VisualStudio.PreviewChangesDialog;
encapsulateField.Invoke();
dialog.VerifyOpen(encapsulateField.DialogName, timeout: HangMitigatingTimeout);
dialog.VerifyOpen(encapsulateField.DialogName, timeout: Helper.HangMitigatingTimeout);
dialog.ClickCancel(encapsulateField.DialogName);
dialog.VerifyClosed(encapsulateField.DialogName);
encapsulateField.Invoke();
dialog.VerifyOpen(encapsulateField.DialogName, timeout: HangMitigatingTimeout);
dialog.VerifyOpen(encapsulateField.DialogName, timeout: Helper.HangMitigatingTimeout);
dialog.ClickApplyAndWaitForFeature(encapsulateField.DialogName, FeatureAttribute.EncapsulateField);
VisualStudio.Editor.Verify.TextContains("public static int? Param { get => param; set => param = value; }");
}
......
......@@ -36,11 +36,11 @@ public void EncapsulateThroughCommand()
var encapsulateField = VisualStudio.EncapsulateField;
var dialog = VisualStudio.PreviewChangesDialog;
encapsulateField.Invoke();
dialog.VerifyOpen(encapsulateField.DialogName, timeout: HangMitigatingTimeout);
dialog.VerifyOpen(encapsulateField.DialogName, timeout: Helper.HangMitigatingTimeout);
dialog.ClickCancel(encapsulateField.DialogName);
dialog.VerifyClosed(encapsulateField.DialogName);
encapsulateField.Invoke();
dialog.VerifyOpen(encapsulateField.DialogName, timeout: HangMitigatingTimeout);
dialog.VerifyOpen(encapsulateField.DialogName, timeout: Helper.HangMitigatingTimeout);
dialog.ClickApplyAndWaitForFeature(encapsulateField.DialogName, FeatureAttribute.EncapsulateField);
VisualStudio.Editor.Verify.TextContains(@" Private _name As Integer? = 0
......
......@@ -10,6 +10,11 @@ namespace Microsoft.VisualStudio.IntegrationTest.Utilities
{
public static class Helper
{
/// <summary>
/// A long timeout used to avoid hangs in tests, where a test failure manifests as an operation never occurring.
/// </summary>
public static readonly TimeSpan HangMitigatingTimeout = TimeSpan.FromMinutes(1);
private static IUIAutomation2 _automation;
public static IUIAutomation2 Automation
......
......@@ -11,6 +11,8 @@ public static class LightBulbHelper
{
public static Task<bool> WaitForLightBulbSessionAsync(ILightBulbBroker broker, IWpfTextView view)
{
var startTime = DateTimeOffset.Now;
return Helper.RetryAsync(async () =>
{
if (broker.IsLightBulbSessionActive(view))
......@@ -18,6 +20,11 @@ public static Task<bool> WaitForLightBulbSessionAsync(ILightBulbBroker broker, I
return true;
}
if (DateTimeOffset.Now > startTime + Helper.HangMitigatingTimeout)
{
throw new InvalidOperationException("Expected a light bulb session to appear.");
}
// checking whether there is any suggested action is async up to editor layer and our waiter doesn't track up to that point.
// so here, we have no other way than sleep (with timeout) to see LB is available.
await Task.Delay(TimeSpan.FromSeconds(1)).ConfigureAwait(true);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册