Skip to content

Commit ca37b3c

Browse files
committed
Make cleanup more robust
Signed-off-by: Adam Wisniewski <awisniew@us.ibm.com>
1 parent 97698c4 commit ca37b3c

File tree

2 files changed

+53
-32
lines changed

2 files changed

+53
-32
lines changed

tests/src/main/java/io/openliberty/tools/eclipse/test/it/LibertyPluginSWTBotMavenWithSpaceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public void afterEach(TestInfo info) {
9292
Assertions.assertNull(launch);
9393

9494
super.afterEach(info);
95-
}
95+
}
9696

9797
@AfterAll
9898
public static void cleanup() throws IOException {

tests/src/main/java/io/openliberty/tools/eclipse/test/it/utils/SWTBotPluginOperations.java

Lines changed: 52 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -178,18 +178,12 @@ public static void disconnectDebugTarget(Object debugTarget) {
178178
* Terminate the launch
179179
*/
180180
public static void terminateLaunch() {
181-
// Don't wrap in syncExec - MagicWidgetFinder methods already handle thread synchronization
182-
// Nested syncExec calls can cause deadlocks in headless CI environments
183-
openDebugPerspective();
184-
showDebugView();
185-
186-
Object debugView = MagicWidgetFinder.findGlobal("Debug");
187-
188-
Object launch = MagicWidgetFinder.find("[Liberty]", debugView,
189-
Option.factory().useContains(true).setThrowExceptionOnNotFound(false).build());
181+
// Use getObjectInDebugView to find the Liberty launch with retry logic
182+
Object launch = getObjectInDebugView("[Liberty]");
190183

191184
// Only attempt to terminate if launch exists
192185
if (launch != null) {
186+
System.out.println("Found Liberty launch, attempting to terminate");
193187
MagicWidgetFinder.context(launch, "Terminate and Remove");
194188

195189
try {
@@ -198,9 +192,11 @@ public static void terminateLaunch() {
198192
MagicWidgetFinder.go("Yes", confirm);
199193
MagicWidgetFinder.pause(3000);
200194
} catch (Exception e) {
201-
// The configrmation pop up window only shows if the launch has not yet been terminated.
195+
// The confirmation pop up window only shows if the launch has not yet been terminated.
202196
// If it has been terminated (or stopped), there is no confirmation.
203197
}
198+
} else {
199+
System.out.println("No Liberty launch found in Debug view to terminate");
204200
}
205201
}
206202

@@ -218,32 +214,57 @@ public static Object getObjectInDebugView(final String objectName) {
218214
openDebugPerspective();
219215
showDebugView();
220216

221-
Object debugView = MagicWidgetFinder.findGlobal("Debug");
222-
223-
// Explicitly activate the Debug view to ensure widgets are properly rendered
224-
// This is critical for headless CI environments
225-
if (debugView instanceof ViewPart) {
226-
final ViewPart vp = (ViewPart) debugView;
227-
Display.getDefault().syncExec(new Runnable() {
228-
@Override
229-
public void run() {
230-
try {
231-
IWorkbench wb = PlatformUI.getWorkbench();
232-
IWorkbenchWindow window = wb.getActiveWorkbenchWindow();
233-
if (window != null && window.getActivePage() != null) {
234-
window.getActivePage().activate(vp);
217+
// Get the Debug view directly using Eclipse API instead of text search
218+
// This is more reliable than findGlobal("Debug") which could find the wrong view
219+
final Object[] debugViewHolder = new Object[1];
220+
Display.getDefault().syncExec(new Runnable() {
221+
@Override
222+
public void run() {
223+
try {
224+
IWorkbench wb = PlatformUI.getWorkbench();
225+
IWorkbenchWindow window = wb.getActiveWorkbenchWindow();
226+
if (window != null && window.getActivePage() != null) {
227+
// Get the Debug view by its ID
228+
ViewPart debugView = (ViewPart) window.getActivePage().findView("org.eclipse.debug.ui.DebugView");
229+
if (debugView != null) {
230+
// Activate it to ensure widgets are rendered
231+
window.getActivePage().activate(debugView);
232+
debugViewHolder[0] = debugView;
235233
}
236-
} catch (Exception e) {
237-
System.err.println("Failed to activate Debug view: " + e.getMessage());
238234
}
235+
} catch (Exception e) {
236+
System.err.println("Failed to get Debug view: " + e.getMessage());
237+
e.printStackTrace();
239238
}
240-
});
241-
// Give the view time to activate
242-
MagicWidgetFinder.pause(500);
239+
}
240+
});
241+
242+
// Give the view time to activate and render
243+
MagicWidgetFinder.pause(500);
244+
245+
Object debugView = debugViewHolder[0];
246+
if (debugView == null) {
247+
System.err.println("Debug view not found, cannot find object: " + objectName);
248+
return null;
249+
}
250+
251+
// Try multiple times to find the object, as it may take time to appear in headless CI
252+
Object result = null;
253+
for (int attempt = 0; attempt < 3 && result == null; attempt++) {
254+
if (attempt > 0) {
255+
System.out.println("Retry attempt " + attempt + " to find object: " + objectName);
256+
MagicWidgetFinder.pause(1000);
257+
}
258+
259+
result = MagicWidgetFinder.find(objectName, debugView,
260+
Option.factory().useContains(true).setThrowExceptionOnNotFound(false).widgetClass(TreeItem.class).build());
261+
}
262+
263+
if (result == null) {
264+
System.out.println("Object not found in Debug view after 3 attempts: " + objectName);
243265
}
244266

245-
return MagicWidgetFinder.find(objectName, debugView,
246-
Option.factory().useContains(true).setThrowExceptionOnNotFound(false).widgetClass(TreeItem.class).build());
267+
return result;
247268
}
248269

249270
/**

0 commit comments

Comments
 (0)