Skip to content

Commit

Permalink
fix erratic test failures in RenameTest (#714)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebthom committed Jul 4, 2023
1 parent d54e911 commit 1b66f91
Showing 1 changed file with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit 1b66f91

Please sign in to comment.