You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by ho...@apache.org on 2022/04/07 20:25:40 UTC

[solr] branch branch_9x updated: SOLR-16143: Fix integration test cleanup & snapshot failure cases (#789)

This is an automated email from the ASF dual-hosted git repository.

houston pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/solr.git


The following commit(s) were added to refs/heads/branch_9x by this push:
     new bb4119c041d SOLR-16143: Fix integration test cleanup & snapshot failure cases (#789)
bb4119c041d is described below

commit bb4119c041d4ad794eeae49a745e073847364b96
Author: Houston Putman <ho...@apache.org>
AuthorDate: Thu Apr 7 16:09:22 2022 -0400

    SOLR-16143: Fix integration test cleanup & snapshot failure cases (#789)
    
    (cherry picked from commit 236613f151b605b2c1d4be9422d2019075555265)
---
 .../org/apache/solr/core/ConfigSetService.java     |  9 +++-----
 solr/packaging/build.gradle                        |  9 +++++++-
 solr/packaging/test/bats_helper.bash               | 25 ++++++++++++++++++++++
 solr/packaging/test/test_auth.bats                 |  2 +-
 solr/packaging/test/test_bats.bats                 |  7 +++++-
 solr/packaging/test/test_create_collection.bats    | 16 ++++++++------
 solr/packaging/test/test_delete_collection.bats    |  5 ++++-
 solr/packaging/test/test_help.bats                 |  2 +-
 solr/packaging/test/test_modules.bats              |  5 ++++-
 solr/packaging/test/test_start_solr.bats           |  5 ++++-
 10 files changed, 66 insertions(+), 19 deletions(-)

diff --git a/solr/core/src/java/org/apache/solr/core/ConfigSetService.java b/solr/core/src/java/org/apache/solr/core/ConfigSetService.java
index 23d154b5f2f..15896926dba 100644
--- a/solr/core/src/java/org/apache/solr/core/ConfigSetService.java
+++ b/solr/core/src/java/org/apache/solr/core/ConfigSetService.java
@@ -193,12 +193,9 @@ public abstract class ConfigSetService {
         String.format(
             Locale.ROOT,
             "Could not find solrconfig.xml at %s, %s or %s",
-            Path.of(configSetDir, "solrconfig.xml").normalize().toAbsolutePath().toString(),
-            Path.of(configSetDir, "conf", "solrconfig.xml").normalize().toAbsolutePath().toString(),
-            Path.of(configSetDir, confDir, "conf", "solrconfig.xml")
-                .normalize()
-                .toAbsolutePath()
-                .toString()));
+            Path.of(confDir, "solrconfig.xml").normalize().toAbsolutePath(),
+            Path.of(confDir, "conf", "solrconfig.xml").normalize().toAbsolutePath(),
+            Path.of(configSetDir, confDir, "conf", "solrconfig.xml").normalize().toAbsolutePath()));
   }
 
   /** If in SolrCloud mode, upload configSets for each SolrCore in solr.xml. */
diff --git a/solr/packaging/build.gradle b/solr/packaging/build.gradle
index 04279e56f75..a96ec79962e 100644
--- a/solr/packaging/build.gradle
+++ b/solr/packaging/build.gradle
@@ -183,19 +183,26 @@ task integrationTests(type: BatsTask) {
 
   def integrationTestOutput = "$buildDir/test-output"
   def solrHome = "$integrationTestOutput/solr-home"
+  def solrTestFailuresDir = "$integrationTestOutput/failure-snapshots"
 
   inputs.dir(distDir)
   outputs.dir(integrationTestOutput)
-  outputs.dir(solrHome)
 
   doFirst {
+    delete integrationTestOutput
+    mkdir integrationTestOutput
+    mkdir solrHome
+    mkdir solrTestFailuresDir
+
     // TODO - if quiet then don't tee
     standardOutput = new TeeOutputStream(System.out, new FileOutputStream("$integrationTestOutput/test-output.txt"))
+
   }
 
   environment SOLR_TIP: distDir.toString()
   environment SOLR_HOME: solrHome
   environment SOLR_LOGS_DIR: "$solrHome/logs"
+  environment TEST_FAILURE_DIR: solrTestFailuresDir
   environment BATS_LIB_PREFIX: "$nodeProjectDir/node_modules"
 }
 
diff --git a/solr/packaging/test/bats_helper.bash b/solr/packaging/test/bats_helper.bash
index da52b973fc7..99f92ded39c 100644
--- a/solr/packaging/test/bats_helper.bash
+++ b/solr/packaging/test/bats_helper.bash
@@ -15,6 +15,10 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+# Use this method when in all "teardown"/"teardownFile" functions and any "setup" functions that should not clear the SOLR_HOME directory.
+# - "teardown"/"teardownFile" usually stop all Solr processes, so you should not clear the SOLR_HOME directory before they are run.
+#   The SOLR_HOME directory will be cleared when the next test file is executed.
+# - "setup" should use "common_setup" if a Solr process is NOT being started in that same "setup" function.
 common_setup() {
     if [ -z ${BATS_LIB_PREFIX:-} ]; then
         # Debugging help, if you want to run bats directly, try to detect where libraries might be
@@ -30,6 +34,27 @@ common_setup() {
     export SOLR_ULIMIT_CHECKS=false
 }
 
+# Use this method in all "setupFile" functions and any "setup" functions that should start with a clean SOLR_HOME directory.
+# - "setupFile" should always start with a clean SOLR_HOME, so "common_clean_setup" should always be used there instead of "common_setup".
+# - "setup" should only use "common_clean_setup" if a Solr Process is created in that same "setup" function.
+common_clean_setup() {
+    common_setup
+
+    if [ -d "${SOLR_HOME}" ]; then
+        rm -r "${SOLR_HOME}"
+        mkdir "${SOLR_HOME}"
+    fi
+}
+
+# Use this method in all "teardown" functions
+save_home_on_failure() {
+    if [[ -z "${BATS_TEST_COMPLETED:-}" ]] && [[ -z "${BATS_TEST_SKIPPED:-}" ]] && [ -d "${SOLR_HOME}" ]; then
+        local solrhome_failure_dir="${TEST_FAILURE_DIR}/${BATS_SUITE_TEST_NUMBER}-${BATS_TEST_NUMBER}"
+        cp -r "${SOLR_HOME}" "${solrhome_failure_dir}"
+        >&2 echo "Please find the SOLR_HOME snapshot for failed test #${BATS_TEST_NUMBER} at: ${solrhome_failure_dir}"
+    fi
+}
+
 delete_all_collections() {
   local collection_list="$(solr zk ls /collections -z localhost:9983)"
   for collection in $collection_list; do
diff --git a/solr/packaging/test/test_auth.bats b/solr/packaging/test/test_auth.bats
index 8c3ba4765ac..666fcb8ee7a 100644
--- a/solr/packaging/test/test_auth.bats
+++ b/solr/packaging/test/test_auth.bats
@@ -18,7 +18,7 @@
 load bats_helper
 
 setup() {
-  common_setup
+  common_clean_setup
 
   run solr auth disable
 }
diff --git a/solr/packaging/test/test_bats.bats b/solr/packaging/test/test_bats.bats
index 53c09544c19..341758e5ff8 100644
--- a/solr/packaging/test/test_bats.bats
+++ b/solr/packaging/test/test_bats.bats
@@ -21,7 +21,7 @@ load bats_helper
 
 setup_file() {
   # set up paths and helpers
-  common_setup
+  common_clean_setup
 
   solr start -c -V
   # echo $output >&3
@@ -37,6 +37,11 @@ teardown_file() {
   # DEBUG : (echo -n "# " ; solr stop -V -all) >&3
 }
 
+teardown() {
+  # save a snapshot of SOLR_HOME for failed tests
+  save_home_on_failure
+}
+
 @test "nothing" {
   # hint: if we need to demonstrate a failing test, change this line to 'false'
   true
diff --git a/solr/packaging/test/test_create_collection.bats b/solr/packaging/test/test_create_collection.bats
index 8430992af43..04ff281aa3f 100644
--- a/solr/packaging/test/test_create_collection.bats
+++ b/solr/packaging/test/test_create_collection.bats
@@ -18,12 +18,8 @@
 load bats_helper
 
 setup_file() {
-  common_setup
+  common_clean_setup
   solr start -c
-
-  local source_configset_dir="$SOLR_TIP/server/solr/configsets/sample_techproducts_configs"
-  test -d $source_configset_dir
-  cp -r $source_configset_dir "$BATS_TMPDIR/config"
 }
 
 teardown_file() {
@@ -36,6 +32,9 @@ setup() {
 }
 
 teardown() {
+  # save a snapshot of SOLR_HOME for failed tests
+  save_home_on_failure
+
   delete_all_collections
 }
 
@@ -55,7 +54,12 @@ teardown() {
 }
 
 @test "accept d option with explicit path to config" {
-  run solr create_collection -c COLL_NAME -d "$BATS_TMPDIR/config"
+  local source_configset_dir="${SOLR_TIP}/server/solr/configsets/sample_techproducts_configs"
+  local dest_configset_dir="${BATS_TEST_TMPDIR}/config"
+  test -d $source_configset_dir
+  cp -r "${source_configset_dir}" "${dest_configset_dir}"
+
+  run solr create_collection -c COLL_NAME -d "${dest_configset_dir}"
   assert_output --partial "Created collection 'COLL_NAME'"
 }
 
diff --git a/solr/packaging/test/test_delete_collection.bats b/solr/packaging/test/test_delete_collection.bats
index 5d3afd9cd84..17afe1ec280 100644
--- a/solr/packaging/test/test_delete_collection.bats
+++ b/solr/packaging/test/test_delete_collection.bats
@@ -18,7 +18,7 @@
 load bats_helper
 
 setup_file() {
-  common_setup
+  common_clean_setup
   solr start -c
 }
 
@@ -32,6 +32,9 @@ setup() {
 }
 
 teardown() {
+  # save a snapshot of SOLR_HOME for failed tests
+  save_home_on_failure
+
   delete_all_collections
 }
 
diff --git a/solr/packaging/test/test_help.bats b/solr/packaging/test/test_help.bats
index b60cff180fd..0bdcb17566f 100644
--- a/solr/packaging/test/test_help.bats
+++ b/solr/packaging/test/test_help.bats
@@ -18,7 +18,7 @@
 load bats_helper
 
 setup() {
-  common_setup
+  common_clean_setup
 }
 
 @test "start help flag prints help" {
diff --git a/solr/packaging/test/test_modules.bats b/solr/packaging/test/test_modules.bats
index 9f8d08ad59b..c9bfaad9210 100644
--- a/solr/packaging/test/test_modules.bats
+++ b/solr/packaging/test/test_modules.bats
@@ -18,10 +18,13 @@
 load bats_helper
 
 setup() {
-  common_setup
+  common_clean_setup
 }
 
 teardown() {
+  # save a snapshot of SOLR_HOME for failed tests
+  save_home_on_failure
+
   delete_all_collections
   solr stop -all >/dev/null 2>&1
 }
diff --git a/solr/packaging/test/test_start_solr.bats b/solr/packaging/test/test_start_solr.bats
index 048f99fc9e1..68469063ff3 100644
--- a/solr/packaging/test/test_start_solr.bats
+++ b/solr/packaging/test/test_start_solr.bats
@@ -18,10 +18,13 @@
 load bats_helper
 
 setup() {
-  common_setup
+  common_clean_setup
 }
 
 teardown() {
+  # save a snapshot of SOLR_HOME for failed tests
+  save_home_on_failure
+
   solr stop -all >/dev/null 2>&1
 }