Skip to content

Commit 94ccde6

Browse files
committed
Migrate RCPTestWorkbenchAdvisor fields to non-static #1517
Converted static fields in RCPTestWorkbenchAdvisor to instance fields to avoid shared state issues between test runs. This ensures each test execution uses a fresh advisor instance with its own state. Updated PlatformUITest to access these fields via the advisor instance.
1 parent 0fc9046 commit 94ccde6

File tree

2 files changed

+24
-35
lines changed

2 files changed

+24
-35
lines changed

tests/org.eclipse.ui.tests.harness/src/org/eclipse/ui/tests/harness/util/RCPTestWorkbenchAdvisor.java

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,23 @@
3636
*/
3737
public class RCPTestWorkbenchAdvisor extends WorkbenchAdvisor {
3838

39-
public static Boolean asyncDuringStartup = null;
39+
public Boolean asyncDuringStartup = null;
4040

4141
// the following fields are set by the threads that attempt sync/asyncs
4242
// during startup.
43-
public static volatile Boolean syncWithDisplayAccess = null;
44-
public static volatile Boolean asyncWithDisplayAccess = null;
45-
public static volatile Boolean syncWithoutDisplayAccess = null;
46-
public static volatile Boolean asyncWithoutDisplayAccess = null;
43+
public volatile Boolean syncWithDisplayAccess = null;
44+
public volatile Boolean asyncWithDisplayAccess = null;
45+
public volatile Boolean syncWithoutDisplayAccess = null;
46+
public volatile Boolean asyncWithoutDisplayAccess = null;
4747

48-
private static boolean started = false;
48+
private boolean started = false;
4949

5050
// CountDownLatch to wait for async/sync operations with DisplayAccess to complete
5151
// We need to wait for 2 operations: asyncWithDisplayAccess and syncWithDisplayAccess
52-
private static CountDownLatch displayAccessLatch = null;
52+
private CountDownLatch displayAccessLatch = null;
5353

54-
public static boolean isSTARTED() {
55-
synchronized (RCPTestWorkbenchAdvisor.class) {
56-
return started;
57-
}
54+
public synchronized boolean isStarted() {
55+
return started;
5856
}
5957

6058
/** Default value of -1 causes the option to be ignored. */
@@ -66,7 +64,7 @@ public static boolean isSTARTED() {
6664
* Traps whether or not calls to displayAccess in the UI thread resulted in
6765
* an exception. Should be false.
6866
*/
69-
public static boolean displayAccessInUIThreadAllowed;
67+
public boolean displayAccessInUIThreadAllowed;
7068

7169
public RCPTestWorkbenchAdvisor() {
7270
// default value means the advisor will not trigger the workbench to
@@ -127,15 +125,6 @@ public void eventLoopIdle(final Display display) {
127125

128126
@Override
129127
public void preStartup() {
130-
synchronized (RCPTestWorkbenchAdvisor.class) {
131-
started = false;
132-
}
133-
asyncDuringStartup = null;
134-
syncWithDisplayAccess = null;
135-
asyncWithDisplayAccess = null;
136-
syncWithoutDisplayAccess = null;
137-
asyncWithoutDisplayAccess = null;
138-
139128
super.preStartup();
140129
final Display display = Display.getCurrent();
141130

@@ -144,14 +133,14 @@ public void preStartup() {
144133

145134
if (display != null) {
146135
display.asyncExec(() -> {
147-
asyncDuringStartup = !isSTARTED();
136+
asyncDuringStartup = !isStarted();
148137
});
149138
}
150139

151140
// start a bunch of threads that are going to do a/sync execs. For some
152141
// of them, call DisplayAccess.accessDisplayDuringStartup. For others,
153142
// dont. Those that call this method should have their runnables invoked
154-
// prior to the method isSTARTED returning true.
143+
// prior to the method isStarted returning true.
155144

156145
setupAsyncDisplayThread(true, display);
157146
setupSyncDisplayThread(true, display);
@@ -176,13 +165,13 @@ public void run() {
176165
try {
177166
display.syncExec(() -> {
178167
if (callDisplayAccess) {
179-
syncWithDisplayAccess = !isSTARTED();
168+
syncWithDisplayAccess = !isStarted();
180169
// Count down after the runnable executes
181170
if (displayAccessLatch != null) {
182171
displayAccessLatch.countDown();
183172
}
184173
} else {
185-
syncWithoutDisplayAccess = !isSTARTED();
174+
syncWithoutDisplayAccess = !isStarted();
186175
}
187176
});
188177
} catch (SWTException e) {
@@ -207,13 +196,13 @@ public void run() {
207196
DisplayAccess.accessDisplayDuringStartup();
208197
display.asyncExec(() -> {
209198
if (callDisplayAccess) {
210-
asyncWithDisplayAccess = !isSTARTED();
199+
asyncWithDisplayAccess = !isStarted();
211200
// Count down after the runnable executes
212201
if (displayAccessLatch != null) {
213202
displayAccessLatch.countDown();
214203
}
215204
} else {
216-
asyncWithoutDisplayAccess = !isSTARTED();
205+
asyncWithoutDisplayAccess = !isStarted();
217206
}
218207
});
219208
}
@@ -243,8 +232,8 @@ public void postStartup() {
243232

244233
// Now mark as started - operations with DisplayAccess should have completed
245234
// Operations without DisplayAccess should still be pending (deferred)
246-
synchronized (RCPTestWorkbenchAdvisor.class) {
235+
synchronized (this) {
247236
started = true;
248237
}
249238
}
250-
}
239+
}

tests/org.eclipse.ui.tests.rcp/Eclipse RCP Tests/org/eclipse/ui/tests/rcp/PlatformUITest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,20 @@ public void testCreateAndRunWorkbench() {
6161
assertTrue(display.isDisposed());
6262

6363
assertAll(//
64-
() -> assertFalse(RCPTestWorkbenchAdvisor.asyncDuringStartup,
64+
() -> assertFalse(wa.asyncDuringStartup,
6565
"Async run during startup. See RCPTestWorkbenchAdvisor.preStartup()"),
6666
// the following four asserts test the various combinations of Thread +
6767
// DisplayAccess + a/sync exec. Anything without a call to DisplayAccess
6868
// should be deferred until after startup.
69-
() -> assertTrue(RCPTestWorkbenchAdvisor.syncWithDisplayAccess,
69+
() -> assertTrue(wa.syncWithDisplayAccess,
7070
"Sync from qualified thread did not run during startup. See RCPTestWorkbenchAdvisor.preStartup()"),
71-
() -> assertTrue(RCPTestWorkbenchAdvisor.asyncWithDisplayAccess,
71+
() -> assertTrue(wa.asyncWithDisplayAccess,
7272
"Async from qualified thread did not run during startup. See RCPTestWorkbenchAdvisor.preStartup()"),
73-
() -> assertFalse(RCPTestWorkbenchAdvisor.syncWithoutDisplayAccess,
73+
() -> assertFalse(wa.syncWithoutDisplayAccess,
7474
"Sync from un-qualified thread ran during startup. See RCPTestWorkbenchAdvisor.preStartup()"),
75-
() -> assertFalse(RCPTestWorkbenchAdvisor.asyncWithoutDisplayAccess,
75+
() -> assertFalse(wa.asyncWithoutDisplayAccess,
7676
"Async from un-qualified thread ran during startup. See RCPTestWorkbenchAdvisor.preStartup()"),
77-
() -> assertFalse(RCPTestWorkbenchAdvisor.displayAccessInUIThreadAllowed,
77+
() -> assertFalse(wa.displayAccessInUIThreadAllowed,
7878
"DisplayAccess.accessDisplayDuringStartup() in UI thread did not result in exception."));
7979
}
8080

0 commit comments

Comments
 (0)