Skip to content

Commit 8d89efc

Browse files
kwinHannesWell
authored andcommitted
Fix tests on Mac OS
Fix several race conditions This closes #1046 This closes #1080
1 parent 6c5ba5d commit 8d89efc

File tree

5 files changed

+38
-9
lines changed

5 files changed

+38
-9
lines changed

org.eclipse.m2e.core.tests/src/org/eclipse/m2e/core/internal/project/registry/MemoryConsumptionTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
package org.eclipse.m2e.core.internal.project.registry;
1515

1616
import java.io.File;
17-
import java.io.FileNotFoundException;
17+
import java.io.IOException;
1818
import java.io.PrintStream;
1919
import java.nio.file.Files;
2020
import java.util.Collections;
@@ -69,7 +69,8 @@ public void testImportLongBuildChain() throws Exception {
6969
waitForJobsToComplete(monitor);
7070
for(IProject p : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
7171
if(p.hasNature(IMavenConstants.NATURE_ID)) {
72-
poms.remove(p.getFile("pom.xml").getLocation().toFile());
72+
File pomFile = p.getFile("pom.xml").getLocation().toFile();
73+
Assert.assertTrue("Could not remove pom path " + pomFile + " from list of projects to be imported: " + poms, poms.remove(pomFile));
7374
}
7475
}
7576
Assert.assertEquals("Some poms were not imported as project", Collections.emptySet(), poms);
@@ -80,13 +81,13 @@ public void testImportLongBuildChain() throws Exception {
8081
}
8182
}
8283

83-
private Set<File> buildLinearHierarchy(int depth, File tempDirectory) throws FileNotFoundException {
84+
private Set<File> buildLinearHierarchy(int depth, File tempDirectory) throws IOException {
8485
Set<File> poms = new HashSet<>(depth, 1.f);
8586
for(int i = 0; i < depth; i++ ) {
8687
File projectDir = new File(tempDirectory, "p" + i);
8788
projectDir.mkdirs();
8889
File pom = new File(projectDir, "pom.xml");
89-
poms.add(pom);
90+
poms.add(pom.getCanonicalFile()); // on Mac OS the temp file is reachable via /var which is a symbolic link to /private/var
9091
try (PrintStream content = new PrintStream(pom);) {
9192
content.println("<project>");
9293
content.println(" <modelVersion>4.0.0</modelVersion>");

org.eclipse.m2e.core.ui.tests/src/org/eclipse/m2e/core/ui/tests/ConsoleTest.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,12 @@ private static void assertDebugeePrintOutAndDebuggerLaunch(IDocument document, S
216216
debugLaunch.getLaunchConfiguration().getType().getIdentifier());
217217
assertEquals(debugLaunchName, debugLaunch.getLaunchConfiguration()
218218
.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, ""));
219-
assertEquals("debug", debugLaunch.getLaunchMode());
220-
assertTrue(debugLaunch.isTerminated());
219+
assertEquals(ILaunchManager.DEBUG_MODE, debugLaunch.getLaunchMode());
220+
long startTime = System.currentTimeMillis();
221+
while (!debugLaunch.isTerminated() && System.currentTimeMillis() - startTime < 10000 ) {
222+
Thread.onSpinWait();
223+
}
224+
assertTrue("Debug launch " + debugLaunch.getLaunchConfiguration().getName() + " is not terminated yet after waiting for 10 seconds", debugLaunch.isTerminated());
221225
}
222226

223227
// --- common utility methods ---

org.eclipse.m2e.editor.lemminx.tests/src/org/eclipse/m2e/editor/lemminx/tests/EditorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public void testGenericEditorHasMavenExtensionEnabled() throws Exception {
9090
Set<Shell> beforeShells = Arrays.stream(display.getShells()).filter(Shell::isVisible).collect(Collectors.toSet());
9191
editorPart.getSelectionProvider().setSelection(new TextSelection(offset, 0));
9292
editorPart.getAction(ITextEditorActionConstants.CONTENT_ASSIST).run();
93-
assertTrue("Missing completion proposals", DisplayHelper.waitForCondition(display, 3000, () -> {
93+
assertTrue("Missing completion proposals", DisplayHelper.waitForCondition(display, 10000, () -> {
9494
Set<Shell> afterShells = Arrays.stream(display.getShells()).filter(Shell::isVisible).collect(Collectors.toSet());
9595
afterShells.removeAll(beforeShells);
9696
return afterShells.stream()

org.eclipse.m2e.jdt.tests/src/org/eclipse/m2e/jdt/tests/RunTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class RunTest extends AbstractMavenProjectTestCase {
3333
@Test
3434
public void testRunTwice() throws Exception {
3535
IProject project = importProject(FileLocator.toFileURL(getClass().getResource("/projects/basicProjectWithDep/pom.xml")).getPath());
36+
waitForJobsToComplete(monitor);
3637
project.build(IncrementalProjectBuilder.FULL_BUILD, null);
3738
ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
3839
ILaunchConfigurationWorkingCopy launchConfig = launchManager.getLaunchConfigurationType(IJavaLaunchConfigurationConstants.ID_JAVA_APPLICATION).newInstance(project, "launch");

pom.xml

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
<name>Maven Integration for Eclipse (root)</name>
2626

2727
<properties>
28-
<tycho.testArgLine>-Xmx800m</tycho.testArgLine>
28+
<tychoDefaultTestArgLine>-Xmx800m</tychoDefaultTestArgLine>
29+
<tycho.testArgLine>${tychoDefaultTestArgLine}</tycho.testArgLine>
2930
<tycho.surefire.timeout>900</tycho.surefire.timeout>
3031
<tycho.surefire.useUIHarness>true</tycho.surefire.useUIHarness>
3132
<tycho.surefire.useUIThread>true</tycho.surefire.useUIThread>
@@ -226,8 +227,30 @@
226227
</activation>
227228
<properties>
228229
<!-- SWT on Mac OS needs to be started on main thread -->
229-
<tycho.testArgLine>-XstartOnFirstThread</tycho.testArgLine>
230+
<tycho.testArgLine>-XstartOnFirstThread ${tychoDefaultTestArgLine}</tycho.testArgLine>
230231
</properties>
232+
<build>
233+
<pluginManagement>
234+
<plugins>
235+
<plugin>
236+
<groupId>org.eclipse.tycho</groupId>
237+
<artifactId>tycho-surefire-plugin</artifactId>
238+
<version>${tycho-version}</version>
239+
<configuration>
240+
<dependencies combine.children="append">
241+
<!--this dependency is needed to detect and set the default VM correctly on Mac OS,
242+
https://github.com/eclipse-jdt/eclipse.jdt.debug/tree/master/org.eclipse.jdt.launching.macosx -->
243+
<dependency>
244+
<artifactId>org.eclipse.jdt.launching.macosx</artifactId>
245+
<type>eclipse-plugin</type>
246+
<version>0.0.0</version>
247+
</dependency>
248+
</dependencies>
249+
</configuration>
250+
</plugin>
251+
</plugins>
252+
</pluginManagement>
253+
</build>
231254
</profile>
232255
<profile>
233256
<id>its</id>

0 commit comments

Comments
 (0)