From 35f1ec8da7682ae0562c62bccb67fc576fecdb41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Kubitz?= Date: Mon, 6 Jan 2025 16:22:23 +0100 Subject: [PATCH] [performance] AbstractJavaModelTests: avoid needless sleep getJavaModel().getJavaProjects() will never return the just created project when inside a workspace operation. JavaSearchScopeTests 39s -> 34s removes also repeated logging "Aborted waitForAutoBuild() because running with the workspace rule" --- .../tests/model/AbstractJavaModelTests.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java index 16a2ae0608b..716e31da649 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java @@ -2324,21 +2324,21 @@ public void run(IProgressMonitor monitor) throws CoreException { IProject sameProject = getWorkspaceRoot().getProject(projectName); assertEquals("Returned project doesn't match same project from workspace: " + sameProject + " vs " + project, sameProject, project); - List javaProjects = List.of(getJavaModel().getJavaProjects()); - boolean foundInModel = javaProjects.stream().anyMatch(p -> projectName.equals(p.getElementName())); - if (!foundInModel) { - try { - Thread.sleep(100); - } catch (InterruptedException e) { - e.printStackTrace(); - } - waitForAutoBuild(); - waitForManualRefresh(); - javaProjects = List.of(getJavaModel().getJavaProjects()); - foundInModel = javaProjects.stream().anyMatch(p -> projectName.equals(p.getElementName())); - } boolean isNestedWorkspaceCall = isWorkspaceRuleAlreadyInUse(getWorkspaceRoot()); if (!isNestedWorkspaceCall) { + List javaProjects = List.of(getJavaModel().getJavaProjects()); + boolean foundInModel = javaProjects.stream().anyMatch(p -> projectName.equals(p.getElementName())); + if (!foundInModel) { + try { + Thread.sleep(100); + } catch (InterruptedException e) { + e.printStackTrace(); + } + waitForAutoBuild(); + waitForManualRefresh(); + javaProjects = List.of(getJavaModel().getJavaProjects()); + foundInModel = javaProjects.stream().anyMatch(p -> projectName.equals(p.getElementName())); + } assertTrue("Project '" + projectName + "' should be present in JavaModel, but we found only: " + javaProjects, foundInModel); } else { // No assert here, caller has to check it *after* the workspace task