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

Wait for design mode before closing a solution #32128

Merged
merged 3 commits into from
Feb 25, 2019
Merged
Changes from all 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 @@ -2,13 +2,15 @@

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using System.Xml.Linq;
using EnvDTE80;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.EditAndContinue;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.VisualStudio.ProjectSystem.Properties;
using Microsoft.VisualStudio.Shell;
Expand Down Expand Up @@ -364,6 +366,12 @@ public void CleanUpOpenSolution()
}
});

if (dte.Debugger.CurrentMode != EnvDTE.dbgDebugMode.dbgDesignMode)
sharwell marked this conversation as resolved.
Show resolved Hide resolved
{
dte.Debugger.TerminateAll();
WaitForDesignMode();
}

CloseSolution();
ErrorList_InProc.Create().WaitForNoErrorsInErrorList();

Expand All @@ -373,6 +381,35 @@ public void CleanUpOpenSolution()
}
}

private static void WaitForDesignMode()
{
var stopwatch = Stopwatch.StartNew();

// This delay was originally added to address test failures in BasicEditAndContinue. When running
// multiple tests in sequence, situations were observed where the Edit and Continue state was not reset:
//
// 1. Test A runs, starts debugging with Edit and Continue
// 2. Test A completes, and the debugger is terminated
// 3. A new project is created for test B
// 4. Test B attempts to set the text for the document created in step (3), but fails
//
// Step (4) was causing test failures because the project created for test B remained in a read-only
// state believing a debugger session was active.
//
// This delay should be replaced with a proper wait condition once the correct one is determined.
var editAndContinueService = GetComponentModelService<IEditAndContinueService>();
do
{
if (stopwatch.Elapsed >= Helper.HangMitigatingTimeout)
{
throw new TimeoutException("Failed to enter design mode in a timely manner.");
}

Thread.Yield();
}
while (editAndContinueService?.DebuggingSession != null);
}

private void CloseSolution()
{
var solution = GetGlobalService<SVsSolution, IVsSolution>();
Expand Down