Skip to content

Commit c891c43

Browse files
committed
Sort out common pool as the possible root cause for test hangs
The test `Test_org_eclipse_swt_custom_BusyIndicator.testShowWhile` hangs on every second build. Let exclude common thread pool as a possible root cause from equation. If the test would continue to fail, this patch can be easily reverted. See #3044
1 parent 72ae11b commit c891c43

1 file changed

Lines changed: 48 additions & 45 deletions

File tree

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_BusyIndicator.java

Lines changed: 48 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -37,58 +37,61 @@ public class Test_org_eclipse_swt_custom_BusyIndicator {
3737
@Test
3838
@Timeout(value = 30)
3939
public void testShowWhile() {
40-
Shell shell = new Shell();
41-
Display display = shell.getDisplay();
42-
Cursor busyCursor = display.getSystemCursor(SWT.CURSOR_WAIT);
43-
CountDownLatch latch = new CountDownLatch(1);
44-
CompletableFuture<?> future = CompletableFuture.runAsync(() -> {
45-
try {
46-
latch.await(10, TimeUnit.SECONDS);
47-
} catch (InterruptedException e) {
48-
}
49-
});
40+
// Executors.newSingleThreadExecutor() hangs on some Linux configurations
41+
try (ExecutorService executor = Executors.newFixedThreadPool(2)){
42+
Shell shell = new Shell();
43+
Display display = shell.getDisplay();
44+
Cursor busyCursor = display.getSystemCursor(SWT.CURSOR_WAIT);
45+
CountDownLatch latch = new CountDownLatch(1);
46+
CompletableFuture<?> future = CompletableFuture.runAsync(() -> {
47+
try {
48+
latch.await(10, TimeUnit.SECONDS);
49+
} catch (InterruptedException e) {
50+
}
51+
}, executor);
5052

51-
CountDownLatch latchNested = new CountDownLatch(1);
52-
CompletableFuture<?> futureNested = CompletableFuture.runAsync(() -> {
53-
try {
54-
latchNested.await(10, TimeUnit.SECONDS);
55-
} catch (InterruptedException e) {
56-
}
57-
});
53+
CountDownLatch latchNested = new CountDownLatch(1);
54+
CompletableFuture<?> futureNested = CompletableFuture.runAsync(() -> {
55+
try {
56+
latchNested.await(10, TimeUnit.SECONDS);
57+
} catch (InterruptedException e) {
58+
}
59+
}, executor);
5860

59-
assertNotEquals(busyCursor, shell.getCursor());
61+
assertNotEquals(busyCursor, shell.getCursor());
6062

61-
// This it proves that events on the display are executed
62-
display.asyncExec(() -> {
63-
// This will happen during the showWhile(future) from below.
64-
BusyIndicator.showWhile(futureNested);
65-
});
63+
// This it proves that events on the display are executed
64+
display.asyncExec(() -> {
65+
// This will happen during the showWhile(future) from below.
66+
BusyIndicator.showWhile(futureNested);
67+
});
6668

67-
Cursor[] cursorInAsync = new Cursor[2];
69+
Cursor[] cursorInAsync = new Cursor[2];
6870

69-
// this serves two purpose:
70-
// 1) it proves that events on the display are executed
71-
// 2) it checks that the shell has the busy cursor during the nest showWhile.
72-
display.asyncExec(() -> {
73-
cursorInAsync[0] = shell.getCursor();
74-
latchNested.countDown();
75-
});
71+
// this serves two purpose:
72+
// 1) it proves that events on the display are executed
73+
// 2) it checks that the shell has the busy cursor during the nest showWhile.
74+
display.asyncExec(() -> {
75+
cursorInAsync[0] = shell.getCursor();
76+
latchNested.countDown();
77+
});
7678

77-
// this serves two purpose:
78-
// 1) it proves that events on the display are executed
79-
// 2) it checks that the shell has the busy cursor even after the termination of
80-
// the nested showWhile.
81-
display.asyncExec(() -> {
82-
cursorInAsync[1] = shell.getCursor();
83-
latch.countDown();
84-
});
79+
// this serves two purpose:
80+
// 1) it proves that events on the display are executed
81+
// 2) it checks that the shell has the busy cursor even after the termination of
82+
// the nested showWhile.
83+
display.asyncExec(() -> {
84+
cursorInAsync[1] = shell.getCursor();
85+
latch.countDown();
86+
});
8587

86-
BusyIndicator.showWhile(future);
87-
assertTrue(future.isDone());
88-
assertEquals(busyCursor, cursorInAsync[0]);
89-
assertEquals(busyCursor, cursorInAsync[1]);
90-
shell.dispose();
91-
while (!display.isDisposed() && display.readAndDispatch()) {
88+
BusyIndicator.showWhile(future);
89+
assertTrue(future.isDone());
90+
assertEquals(busyCursor, cursorInAsync[0]);
91+
assertEquals(busyCursor, cursorInAsync[1]);
92+
shell.dispose();
93+
while (!display.isDisposed() && display.readAndDispatch()) {
94+
}
9295
}
9396
}
9497

0 commit comments

Comments
 (0)