diff --git a/x-pack/plugin/snapshot-repo-test-kit/src/main/java/org/elasticsearch/repositories/blobstore/testkit/RepositoryAnalyzeAction.java b/x-pack/plugin/snapshot-repo-test-kit/src/main/java/org/elasticsearch/repositories/blobstore/testkit/RepositoryAnalyzeAction.java index f71ad161aa865..2facbfd8f460c 100644 --- a/x-pack/plugin/snapshot-repo-test-kit/src/main/java/org/elasticsearch/repositories/blobstore/testkit/RepositoryAnalyzeAction.java +++ b/x-pack/plugin/snapshot-repo-test-kit/src/main/java/org/elasticsearch/repositories/blobstore/testkit/RepositoryAnalyzeAction.java @@ -437,22 +437,10 @@ private void fail(Exception e) { } /** - * Check that we haven't already failed or been cancelled or timed out; if newly cancelled or timed out then record this as the root - * cause of failure. + * Check that we haven't already failed (including cancellation and timing out). */ private boolean isRunning() { - if (failure.get() != null) { - return false; - } - - if (task.isCancelled()) { - setFirstFailure(new RepositoryVerificationException(request.repositoryName, "verification cancelled")); - // if this CAS failed then we're failing for some other reason, nbd; also if the task is cancelled then its descendants are - // also cancelled, so no further action is needed either way. - return false; - } - - return true; + return failure.get() == null; } private class CheckForCancelListener implements ActionListener { @@ -485,6 +473,8 @@ public void run() { cancellationListener.addTimeout(request.getTimeout(), repository.threadPool(), EsExecutors.DIRECT_EXECUTOR_SERVICE); cancellationListener.addListener(new CheckForCancelListener()); + task.addListener(() -> setFirstFailure(new RepositoryVerificationException(request.repositoryName, "analysis cancelled"))); + final Random random = new Random(request.getSeed()); final List nodes = getSnapshotNodes(discoveryNodes);