diff --git a/org.eclipse.lsp4e.test/src/org/eclipse/lsp4e/test/rename/RenameTest.java b/org.eclipse.lsp4e.test/src/org/eclipse/lsp4e/test/rename/RenameTest.java index 357fdca6a..4d6d43483 100644 --- a/org.eclipse.lsp4e.test/src/org/eclipse/lsp4e/test/rename/RenameTest.java +++ b/org.eclipse.lsp4e.test/src/org/eclipse/lsp4e/test/rename/RenameTest.java @@ -80,32 +80,35 @@ public void testRenameHandlerEnablement() throws Exception { editor.selectAndReveal(1, 0); ICommandService commandService = PlatformUI.getWorkbench().getService(ICommandService.class); Command command = commandService.getCommand(IWorkbenchCommandConstants.FILE_RENAME); - assertTrue(command.isEnabled()); + + waitForAndAssertCondition(2_000, () -> command.isEnabled()); assertTrue(command.isHandled()); } @Test public void testAsyncRenameHandlerEnablement() throws Exception { - long delay = 2000; + final int delay = 2_000; // this fixed value is not really an optimal solution, since it depends on the following things // to happen within that time frame. Should maybe re-work this in the future towards a more // precise way of steering the execution from the test here - MockLanguageServer.INSTANCE.setTimeToProceedQueries(delay); - IProject project = TestUtils.createProject("blah"); - IFile file = TestUtils.createUniqueTestFile(project, "old"); - ITextEditor editor = (ITextEditor) TestUtils.openEditor(file); - editor.selectAndReveal(1, 0); - ICommandService commandService = PlatformUI.getWorkbench().getService(ICommandService.class); - Command command = commandService.getCommand(IWorkbenchCommandConstants.FILE_RENAME); - assertFalse(command.isEnabled() && command.isHandled()); + try { + IProject project = TestUtils.createProject("blah"); + IFile file = TestUtils.createUniqueTestFile(project, "old"); + ITextEditor editor = (ITextEditor) TestUtils.openEditor(file); + editor.selectAndReveal(1, 0); - Thread.sleep(delay * 3); + ICommandService commandService = PlatformUI.getWorkbench().getService(ICommandService.class); + Command command = commandService.getCommand(IWorkbenchCommandConstants.FILE_RENAME); + assertFalse(command.isEnabled()); - // Put back so shutdown doesn't time out - MockLanguageServer.INSTANCE.setTimeToProceedQueries(0); - assertTrue(command.isEnabled() && command.isHandled()); + waitForAndAssertCondition(3 * delay, () -> command.isEnabled()); + assertTrue(command.isHandled()); + } finally { + // Put back so shutdown doesn't time out + MockLanguageServer.INSTANCE.setTimeToProceedQueries(0); + } } @Test @@ -266,7 +269,7 @@ public void testPlaceholderUsingPlaceholderFromPrepareRenameResult() throws Exce IDocument document = LSPEclipseUtils.getDocument(file); assertNotNull(document); LSPRenameProcessor processor = new LSPRenameProcessor(document, 0); - + try { processor.checkInitialConditions(new NullProgressMonitor()); } catch (CoreException e) { @@ -285,7 +288,7 @@ public void testPlaceholderUsingRangeFromPrepareRenameResult() throws Exception IDocument document = LSPEclipseUtils.getDocument(file); assertNotNull(document); LSPRenameProcessor processor = new LSPRenameProcessor(document, 0); - + try { processor.checkInitialConditions(new NullProgressMonitor()); } catch (CoreException e) {