diff --git a/src/VisualStudio/IntegrationTest/TestUtilities/InProcess/SolutionExplorer_InProc.cs b/src/VisualStudio/IntegrationTest/TestUtilities/InProcess/SolutionExplorer_InProc.cs index 26d4987b31355..07731525a7210 100644 --- a/src/VisualStudio/IntegrationTest/TestUtilities/InProcess/SolutionExplorer_InProc.cs +++ b/src/VisualStudio/IntegrationTest/TestUtilities/InProcess/SolutionExplorer_InProc.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; using System.Runtime.InteropServices; @@ -9,6 +10,7 @@ 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; @@ -364,6 +366,12 @@ public void CleanUpOpenSolution() } }); + if (dte.Debugger.CurrentMode != EnvDTE.dbgDebugMode.dbgDesignMode) + { + dte.Debugger.TerminateAll(); + WaitForDesignMode(); + } + CloseSolution(); ErrorList_InProc.Create().WaitForNoErrorsInErrorList(); @@ -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(); + 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();