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

fix erratic test failures in RenameTest #714

Merged
merged 1 commit into from
Jul 4, 2023
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 @@ -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