Skip to content

Commit

Permalink
Remove empty if/try-finally in base integ test class (opensearch-proj…
Browse files Browse the repository at this point in the history
…ect#9098)

The [commit to comment out `forceFailure()`][1] was done about 8 years
ago so I don't think we'll be bringing it back. Also this makes the code
base a slightly friendlier place :)

[1]: opensearch-project@e5a699f

Signed-off-by: Andrew Ross <andrross@amazon.com>
  • Loading branch information
andrross committed Aug 3, 2023
1 parent 56a19ea commit 6e51c47
Showing 1 changed file with 21 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -590,44 +590,34 @@ private static void clearClusters() throws Exception {
}

private void afterInternal(boolean afterClass) throws Exception {
boolean success = false;
final Scope currentClusterScope = getCurrentClusterScope();
if (isInternalCluster()) {
internalCluster().clearDisruptionScheme();
}
try {
final Scope currentClusterScope = getCurrentClusterScope();
if (isInternalCluster()) {
internalCluster().clearDisruptionScheme();
}
try {
if (cluster() != null) {
if (currentClusterScope != Scope.TEST) {
Metadata metadata = client().admin().cluster().prepareState().execute().actionGet().getState().getMetadata();
if (cluster() != null) {
if (currentClusterScope != Scope.TEST) {
Metadata metadata = client().admin().cluster().prepareState().execute().actionGet().getState().getMetadata();

final Set<String> persistentKeys = new HashSet<>(metadata.persistentSettings().keySet());
assertThat("test leaves persistent cluster metadata behind", persistentKeys, empty());
final Set<String> persistentKeys = new HashSet<>(metadata.persistentSettings().keySet());
assertThat("test leaves persistent cluster metadata behind", persistentKeys, empty());

final Set<String> transientKeys = new HashSet<>(metadata.transientSettings().keySet());
assertThat("test leaves transient cluster metadata behind", transientKeys, empty());
}
ensureClusterSizeConsistency();
ensureClusterStateConsistency();
ensureClusterStateCanBeReadByNodeTool();
beforeIndexDeletion();
cluster().wipe(excludeTemplates()); // wipe after to make sure we fail in the test that didn't ack the delete
if (afterClass || currentClusterScope == Scope.TEST) {
cluster().close();
}
cluster().assertAfterTest();
final Set<String> transientKeys = new HashSet<>(metadata.transientSettings().keySet());
assertThat("test leaves transient cluster metadata behind", transientKeys, empty());
}
} finally {
if (currentClusterScope == Scope.TEST) {
clearClusters(); // it is ok to leave persistent / transient cluster state behind if scope is TEST
ensureClusterSizeConsistency();
ensureClusterStateConsistency();
ensureClusterStateCanBeReadByNodeTool();
beforeIndexDeletion();
cluster().wipe(excludeTemplates()); // wipe after to make sure we fail in the test that didn't ack the delete
if (afterClass || currentClusterScope == Scope.TEST) {
cluster().close();
}
cluster().assertAfterTest();
}
success = true;
} finally {
if (!success) {
// if we failed here that means that something broke horribly so we should clear all clusters
// TODO: just let the exception happen, WTF is all this horseshit
// afterTestRule.forceFailure();
if (currentClusterScope == Scope.TEST) {
clearClusters(); // it is ok to leave persistent / transient cluster state behind if scope is TEST
}
}
}
Expand Down

0 comments on commit 6e51c47

Please sign in to comment.