Skip to content

Commit

Permalink
[TEST] Wait to lose master in Readiness tests (#86696) (#86991)
Browse files Browse the repository at this point in the history
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
grcevski and elasticmachine committed May 20, 2022
1 parent 381a847 commit 699cbd4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.elasticsearch.test.readiness.ReadinessClientProbe;

import java.util.List;
import java.util.concurrent.TimeUnit;

import static org.elasticsearch.test.NodeRoles.dataOnlyNode;
import static org.elasticsearch.test.NodeRoles.masterNode;
Expand Down Expand Up @@ -133,6 +134,7 @@ public Settings onNodeStopped(String nodeName) throws Exception {

for (String dataNode : dataNodes) {
ReadinessService s = internalCluster().getInstance(ReadinessService.class, dataNode);
s.listenerThreadLatch.await(10, TimeUnit.SECONDS);
tcpReadinessProbeFalse(s);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public class ReadinessService extends AbstractLifecycleComponent implements Clus

private volatile boolean active; // false;
private volatile ServerSocketChannel serverChannel;
private CountDownLatch listenerThreadLatch;
// package private for testing
volatile CountDownLatch listenerThreadLatch = new CountDownLatch(0);
final AtomicReference<InetSocketAddress> boundSocket = new AtomicReference<>();
private final Collection<BoundAddressListener> boundAddressListeners = new CopyOnWriteArrayList<>();

Expand Down Expand Up @@ -152,7 +153,7 @@ synchronized void startListener() {
this.listenerThreadLatch = new CountDownLatch(1);

new Thread(() -> {
assert serverChannel != null && listenerThreadLatch != null;
assert serverChannel != null;
try {
while (serverChannel.isOpen()) {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
Expand Down

0 comments on commit 699cbd4

Please sign in to comment.