Skip to content

Commit 3e5d822

Browse files
committed
EventServiceTest: try to speed up a test
We do not need to _always_ wait 500 ms, but rather can try waiting for a notification from the other thread. Given the overhead of queuing things onto the EDT, it turns out that the test thread does end up waiting before the EDT notifies. So in practice it should cut down on how long the test takes to run. Suggested by Johannes Schindelin.
1 parent c7fb828 commit 3e5d822

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/test/java/org/scijava/event/EventServiceTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ public void testEventHandlerDependencies() throws InterruptedException {
8989
final ServiceNeedingAnEventService snaeService =
9090
context.getService(ServiceNeedingAnEventService.class);
9191
assertNotNull(eventService);
92-
Thread.sleep(500); // NB: ServicesLoadedEvent is published asynchronously.
92+
// NB: ServicesLoadedEvent is published asynchronously.
93+
synchronized (snaeService) {
94+
snaeService.wait(500);
95+
}
9396
assertTrue(snaeService.isContextCreated());
9497
}
9598

@@ -127,6 +130,9 @@ public void onEvent(
127130
@SuppressWarnings("unused") final ServicesLoadedEvent evt)
128131
{
129132
contextCreated = true;
133+
synchronized (this) {
134+
notifyAll();
135+
}
130136
}
131137
}
132138

0 commit comments

Comments
 (0)