Apache Solr open-source search software
SOLR-16143: Fix integration test cleanup & snapshot failure cases (#789)
Houston Putman236613f151b6
diff --git a/solr/core/src/java/org/apache/solr/core/ConfigSetService.java b/solr/core/src/java/org/apache/solr/core/ConfigSetService.javaindex 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.gradleindex 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 teestandardOutput = new TeeOutputStream(System.out, new FileOutputStream("$integrationTestOutput/test-output.txt"))+}environment SOLR_TIP: distDir.toString()environment SOLR_HOME: solrHomeenvironment SOLR_LOGS_DIR: "$solrHome/logs"+ environment TEST_FAILURE_DIR: solrTestFailuresDirenvironment BATS_LIB_PREFIX: "$nodeProjectDir/node_modules"}diff --git a/solr/packaging/test/bats_helper.bash b/solr/packaging/test/bats_helper.bashindex 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; dodiff --git a/solr/packaging/test/test_auth.bats b/solr/packaging/test/test_auth.batsindex 8c3ba4765ac..666fcb8ee7a 100644--- a/solr/packaging/test/test_auth.bats+++ b/solr/packaging/test/test_auth.bats@@ -18,7 +18,7 @@load bats_helpersetup() {- common_setup+ common_clean_setuprun solr auth disable}diff --git a/solr/packaging/test/test_bats.bats b/solr/packaging/test/test_bats.batsindex 53c09544c19..341758e5ff8 100644--- a/solr/packaging/test/test_bats.bats+++ b/solr/packaging/test/test_bats.bats@@ -21,7 +21,7 @@ load bats_helpersetup_file() {# set up paths and helpers- common_setup+ common_clean_setupsolr 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'truediff --git a/solr/packaging/test/test_create_collection.bats b/solr/packaging/test/test_create_collection.batsindex 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_helpersetup_file() {- common_setup+ common_clean_setupsolr 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.batsindex 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_helpersetup_file() {- common_setup+ common_clean_setupsolr 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.batsindex b60cff180fd..0bdcb17566f 100644--- a/solr/packaging/test/test_help.bats+++ b/solr/packaging/test/test_help.bats@@ -18,7 +18,7 @@load bats_helpersetup() {- 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.batsindex 9f8d08ad59b..c9bfaad9210 100644--- a/solr/packaging/test/test_modules.bats+++ b/solr/packaging/test/test_modules.bats@@ -18,10 +18,13 @@load bats_helpersetup() {- common_setup+ common_clean_setup}teardown() {+ # save a snapshot of SOLR_HOME for failed tests+ save_home_on_failure+delete_all_collectionssolr stop -all >/dev/null 2>&1}diff --git a/solr/packaging/test/test_start_solr.bats b/solr/packaging/test/test_start_solr.batsindex 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_helpersetup() {- 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}