Skip to content

Commit

Permalink
Make RemoteClusterConnectionTests more robust against cancelable thre…
Browse files Browse the repository at this point in the history
…ads aborts

Today we assert hart if failure listeners are invoked more than once. Yet, this
can happen if we cancel the execution since the caller and the handler will get
the exception on the cancelable threads and will notify the listener concurrently
if timinig allows. This commit relaxes the assertion towards handling multiple
invocations with `ExecutionCancelledException`

Closes #24010
Closes #24179
Closes vagnerclementino/elasticsearch/#98
  • Loading branch information
s1monw committed May 16, 2017
1 parent 6ce597a commit f9cfe86
Showing 1 changed file with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ public void run() {
barrier.await();
CountDownLatch latch = new CountDownLatch(numConnectionAttempts);
for (int i = 0; i < numConnectionAttempts; i++) {
AtomicReference<RuntimeException> executed = new AtomicReference<>();
AtomicReference<Exception> executed = new AtomicReference<>();
ActionListener<Void> listener = ActionListener.wrap(
x -> {
if (executed.compareAndSet(null, new RuntimeException())) {
Expand All @@ -508,10 +508,21 @@ public void run() {
}
},
x -> {
if (executed.compareAndSet(null, new RuntimeException())) {
if (executed.compareAndSet(null, x)) {
latch.countDown();
} else {
throw new AssertionError("shit's been called twice", executed.get());
final String message = x.getMessage();
if ((executed.get().getClass() == x.getClass()
&& "operation was cancelled reason [connect handler is closed]".equals(message)
&& message.equals(executed.get().getMessage())) == false) {
// we do cancel the operation and that means that if timing allows it, the caller
// of a blocking call as well as the handler will get the exception from the
// ExecutionCancelledException concurrently. unless that is the case we fail
// if we get called more than once!
AssertionError assertionError = new AssertionError("shit's been called twice", x);
assertionError.addSuppressed(executed.get());
throw assertionError;
}
}
if (x instanceof RejectedExecutionException || x instanceof AlreadyClosedException
|| x instanceof CancellableThreads.ExecutionCancelledException) {
Expand Down

0 comments on commit f9cfe86

Please sign in to comment.