Skip to content

Commit 590cbbc

Browse files
Invoke TestCluster#assertAfterTest before closing the cluster (elastic#122639) (elastic#122711)
In test-scoped internal ITs the `cluster().assertAfterTest()` method was invoked *after* the cluster nodes were closed. Consequently, the assertions that iterated over the internal nodes (and asserted some state on nodes after the test) were all effectively noops. This PR reverses that order, so that after-test assertions are effective again.
1 parent fba4d61 commit 590cbbc

File tree

3 files changed

+41
-24
lines changed

3 files changed

+41
-24
lines changed

server/src/internalClusterTest/java/org/elasticsearch/cluster/PrevalidateNodeRemovalIT.java

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -179,28 +179,35 @@ public void testNodeRemovalFromRedClusterWithTimeout() throws Exception {
179179
// make it red!
180180
internalCluster().stopNode(node1);
181181
ensureRed(indexName);
182+
CountDownLatch stallPrevalidateShardPathActionLatch = new CountDownLatch(1);
182183
MockTransportService.getInstance(node2)
183184
.addRequestHandlingBehavior(TransportPrevalidateShardPathAction.ACTION_NAME + "[n]", (handler, request, channel, task) -> {
184185
logger.info("drop the check shards request");
186+
safeAwait(stallPrevalidateShardPathActionLatch);
187+
handler.messageReceived(request, channel, task);
185188
});
186-
PrevalidateNodeRemovalRequest req = PrevalidateNodeRemovalRequest.builder()
187-
.setNames(node2)
188-
.build(TEST_REQUEST_TIMEOUT)
189-
.masterNodeTimeout(TimeValue.timeValueSeconds(1))
190-
.timeout(TimeValue.timeValueSeconds(1));
191-
PrevalidateNodeRemovalResponse resp = client().execute(PrevalidateNodeRemovalAction.INSTANCE, req).get();
192-
assertFalse("prevalidation result should return false", resp.getPrevalidation().isSafe());
193-
String node2Id = getNodeId(node2);
194-
assertThat(
195-
resp.getPrevalidation().message(),
196-
equalTo("cannot prevalidate removal of nodes with the following IDs: [" + node2Id + "]")
197-
);
198-
assertThat(resp.getPrevalidation().nodes().size(), equalTo(1));
199-
NodesRemovalPrevalidation.NodeResult nodeResult = resp.getPrevalidation().nodes().get(0);
200-
assertThat(nodeResult.name(), equalTo(node2));
201-
assertFalse(nodeResult.result().isSafe());
202-
assertThat(nodeResult.result().message(), startsWith("failed contacting the node"));
203-
assertThat(nodeResult.result().reason(), equalTo(NodesRemovalPrevalidation.Reason.UNABLE_TO_VERIFY));
189+
try {
190+
PrevalidateNodeRemovalRequest req = PrevalidateNodeRemovalRequest.builder()
191+
.setNames(node2)
192+
.build(TEST_REQUEST_TIMEOUT)
193+
.masterNodeTimeout(TimeValue.timeValueSeconds(1))
194+
.timeout(TimeValue.timeValueSeconds(1));
195+
PrevalidateNodeRemovalResponse resp = client().execute(PrevalidateNodeRemovalAction.INSTANCE, req).get();
196+
assertFalse("prevalidation result should return false", resp.getPrevalidation().isSafe());
197+
String node2Id = getNodeId(node2);
198+
assertThat(
199+
resp.getPrevalidation().message(),
200+
equalTo("cannot prevalidate removal of nodes with the following IDs: [" + node2Id + "]")
201+
);
202+
assertThat(resp.getPrevalidation().nodes().size(), equalTo(1));
203+
NodesRemovalPrevalidation.NodeResult nodeResult = resp.getPrevalidation().nodes().get(0);
204+
assertThat(nodeResult.name(), equalTo(node2));
205+
assertFalse(nodeResult.result().isSafe());
206+
assertThat(nodeResult.result().message(), startsWith("failed contacting the node"));
207+
assertThat(nodeResult.result().reason(), equalTo(NodesRemovalPrevalidation.Reason.UNABLE_TO_VERIFY));
208+
} finally {
209+
stallPrevalidateShardPathActionLatch.countDown();
210+
}
204211
}
205212

206213
private void ensureRed(String indexName) throws Exception {

test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,10 +585,10 @@ private void afterInternal(boolean afterClass) throws Exception {
585585
ensureClusterInfoServiceRunning();
586586
beforeIndexDeletion();
587587
cluster().wipe(excludeTemplates()); // wipe after to make sure we fail in the test that didn't ack the delete
588+
cluster().assertAfterTest();
588589
if (afterClass || currentClusterScope == Scope.TEST) {
589590
cluster().close();
590591
}
591-
cluster().assertAfterTest();
592592
}
593593
} finally {
594594
if (currentClusterScope == Scope.TEST) {

x-pack/plugin/security/src/internalClusterTest/java/org/elasticsearch/xpack/security/UnregisteredSettingsIntegTests.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,28 @@
1111
import org.elasticsearch.test.ESIntegTestCase;
1212
import org.elasticsearch.test.SecurityIntegTestCase;
1313

14+
import java.io.IOException;
15+
1416
import static org.elasticsearch.test.NodeRoles.dataOnlyNode;
1517
import static org.elasticsearch.test.NodeRoles.masterNode;
1618
import static org.hamcrest.Matchers.containsString;
1719

1820
@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0, autoManageMasterNodes = false)
1921
public class UnregisteredSettingsIntegTests extends SecurityIntegTestCase {
2022

21-
public void testIncludeReservedRolesSettingNotRegistered() {
23+
public void testIncludeReservedRolesSettingNotRegistered() throws IOException {
2224
internalCluster().setBootstrapMasterNodeIndex(0);
2325

2426
final Settings.Builder builder = Settings.builder()
2527
.put(randomBoolean() ? masterNode() : dataOnlyNode())
2628
.putList("xpack.security.reserved_roles.include", "superuser");
2729

28-
final IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> internalCluster().startNode(builder));
29-
assertThat(e.getMessage(), containsString("unknown setting [xpack.security.reserved_roles.include]"));
30+
try {
31+
final IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> internalCluster().startNode(builder));
32+
assertThat(e.getMessage(), containsString("unknown setting [xpack.security.reserved_roles.include]"));
33+
} finally {
34+
internalCluster().close();
35+
}
3036
}
3137

3238
public void testSamlExcludeRolesSettingNotRegistered() throws Exception {
@@ -36,7 +42,11 @@ public void testSamlExcludeRolesSettingNotRegistered() throws Exception {
3642
.put(randomBoolean() ? masterNode() : dataOnlyNode())
3743
.putList("xpack.security.authc.realms.saml.saml1.exclude_roles", "superuser");
3844

39-
final IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> internalCluster().startNode(builder));
40-
assertThat(e.getMessage(), containsString("unknown setting [xpack.security.authc.realms.saml.saml1.exclude_roles]"));
45+
try {
46+
final IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> internalCluster().startNode(builder));
47+
assertThat(e.getMessage(), containsString("unknown setting [xpack.security.authc.realms.saml.saml1.exclude_roles]"));
48+
} finally {
49+
internalCluster().close();
50+
}
4151
}
4252
}

0 commit comments

Comments
 (0)