From ba5b4f1413157b2d6bead28194769b5bd683b5d8 Mon Sep 17 00:00:00 2001 From: Jay Modi Date: Thu, 14 Nov 2019 13:06:58 -0700 Subject: [PATCH] ESIntegTestCase always cleans up static fields (#49105) ESIntegTestCase has logic to clean up static fields in a method annotated with `@AfterClass` so that these fields do not trigger the StaticFieldsInvariantRule. However, during the exceptional close of the test cluster, this cleanup can be missed. The StaticFieldsInvariantRule always runs and will attempt to inspect the size of the static fields that were not cleaned up. If the `currentCluster` field of ESIntegTestCase references an InternalTestCluster, this could hold a reference to an implementation of a `Path` that comes from the `sun.nio.fs` package, which the security manager will deny access to. This casues additional noise to be generated since the AccessControlException will cause the StaticFieldsInvariantRule to fail and also be reported along with the actual exception that occurred. This change clears the static fields of ESIntegTestCase in a finally block inside the `@AfterClass` method to prevent this unnecessary noise. Closes #41526 --- .../org/elasticsearch/test/ESIntegTestCase.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java index e855636af15a1..aa25134a42988 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java @@ -1947,19 +1947,19 @@ public final void cleanUpCluster() throws Exception { @AfterClass public static void afterClass() throws Exception { - if (!runTestScopeLifecycle()) { - try { + try { + if (runTestScopeLifecycle()) { + clearClusters(); + } else { INSTANCE.printTestMessage("cleaning up after"); INSTANCE.afterInternal(true); checkStaticState(true); - } finally { - INSTANCE = null; } - } else { - clearClusters(); + } finally { + SUITE_SEED = null; + currentCluster = null; + INSTANCE = null; } - SUITE_SEED = null; - currentCluster = null; } private static void initializeSuiteScope() throws Exception {