Skip to content

Commit 269a7f6

Browse files
committed
[grid] use a single event listener for the event-bus health check
1 parent de88a12 commit 269a7f6

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

java/src/org/openqa/selenium/grid/commands/EventBusCommand.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
import com.google.auto.service.AutoService;
2727
import com.google.common.collect.ImmutableMap;
2828
import com.google.common.collect.ImmutableSet;
29+
import java.util.ArrayList;
2930
import java.util.Collections;
31+
import java.util.List;
3032
import java.util.Set;
3133
import java.util.concurrent.CountDownLatch;
3234
import java.util.concurrent.TimeUnit;
@@ -107,6 +109,24 @@ public Server<?> asServer(Config initialConfig) {
107109
EventBus bus = events.getEventBus();
108110

109111
BaseServerOptions serverOptions = new BaseServerOptions(config);
112+
List<CountDownLatch> pending = new ArrayList<>();
113+
114+
EventName healthCheck = new EventName("healthcheck");
115+
bus.addListener(
116+
new EventListener<>(
117+
healthCheck,
118+
Object.class,
119+
obj -> {
120+
synchronized (pending) {
121+
// Concurrent health checks might influence each other, we can ignore this.
122+
// We only want to see any event is delivered to tell the bus is healthy.
123+
pending.removeIf(
124+
latch -> {
125+
latch.countDown();
126+
return true;
127+
});
128+
}
129+
}));
110130

111131
return new NettyServer(
112132
serverOptions,
@@ -117,10 +137,10 @@ public Server<?> asServer(Config initialConfig) {
117137
req -> {
118138
CountDownLatch latch = new CountDownLatch(1);
119139

120-
EventName healthCheck = new EventName("healthcheck");
121-
bus.addListener(
122-
new EventListener<>(
123-
healthCheck, Object.class, obj -> latch.countDown()));
140+
synchronized (pending) {
141+
pending.add(latch);
142+
}
143+
124144
bus.fire(new Event(healthCheck, "ping"));
125145

126146
try {

0 commit comments

Comments
 (0)