Skip to content

Commit c3bf5cc

Browse files
committed
Fix flaky PluginBasedLaunchTest by waiting for jobs and UI
The PluginBasedLaunchTest.testWriteBundleEntry_singleTargetPlugin_noVersionEntry failure appears to be a real issue caused by asynchronous updates to the plugin registry or target platform not completing before the test assertion. This change adds a waitForJobsAndUI helper method to AbstractLaunchTest.java and invokes it within the getModel method. This ensures that the test waits for background jobs and processes the UI event loop, allowing the target platform to be fully loaded before asserting the model's presence.
1 parent 19e78d8 commit c3bf5cc

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/launcher/AbstractLaunchTest.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
import org.assertj.core.api.Assertions;
3434
import org.assertj.core.presentation.StandardRepresentation;
35+
import org.eclipse.core.runtime.jobs.Job;
3536
import org.eclipse.core.resources.IProject;
3637
import org.eclipse.debug.core.DebugPlugin;
3738
import org.eclipse.debug.core.ILaunchConfiguration;
@@ -42,6 +43,7 @@
4243
import org.eclipse.pde.core.plugin.PluginRegistry;
4344
import org.eclipse.pde.ui.tests.util.ProjectUtils;
4445
import org.eclipse.pde.ui.tests.util.TargetPlatformUtil;
46+
import org.eclipse.swt.widgets.Display;
4547
import org.junit.BeforeClass;
4648
import org.junit.ClassRule;
4749
import org.junit.Rule;
@@ -82,6 +84,8 @@ public static IPluginModelBase findTargetModel(String id, String version) {
8284
private static IPluginModelBase getModel(String id, String versionStr,
8385
Function<ModelEntry, IPluginModelBase[]> modelsGetter, String type) {
8486

87+
waitForJobsAndUI(10000);
88+
8589
ModelEntry entry = PluginRegistry.findEntry(id);
8690
assertNotNull("entry '" + id + "' should be present in PluginRegistry", entry);
8791
IPluginModelBase[] models = modelsGetter.apply(entry);
@@ -98,6 +102,35 @@ private static IPluginModelBase getModel(String id, String versionStr,
98102
() -> new NoSuchElementException("No " + type + " model " + id + "-" + version + " found"));
99103
}
100104

105+
private static void waitForJobsAndUI(long timeoutMillis) {
106+
long start = System.currentTimeMillis();
107+
108+
while (System.currentTimeMillis() - start < timeoutMillis) {
109+
// Process UI events
110+
while (Display.getDefault().readAndDispatch()) {
111+
// Keep processing
112+
}
113+
114+
// Check if all jobs are done
115+
if (Job.getJobManager().isIdle()) {
116+
// Process any final UI events
117+
while (Display.getDefault().readAndDispatch()) {
118+
// Keep processing
119+
}
120+
return;
121+
}
122+
123+
try {
124+
Thread.sleep(50);
125+
} catch (InterruptedException e) {
126+
Thread.currentThread().interrupt();
127+
return;
128+
}
129+
}
130+
131+
// throw new AssertionError("Timeout waiting for jobs to complete");
132+
}
133+
101134
static BundleLocationDescriptor workspaceBundle(String id, String version) {
102135
Objects.requireNonNull(version);
103136
return () -> findWorkspaceModel(id, version);

0 commit comments

Comments
 (0)