From 49baa84cfc7abdede0ada5ed2e310147ab6663c3 Mon Sep 17 00:00:00 2001 From: Sebastian Sura Date: Thu, 23 May 2024 15:17:38 +0200 Subject: [PATCH] dbcheck-test: add test for dbcheck --- systemtests/scripts/functions | 2 +- systemtests/tests/CMakeLists.txt | 1 + systemtests/tests/dbcheck/CMakeLists.txt | 21 +++++++ systemtests/tests/dbcheck/test-setup | 32 ++++++++++ .../tests/dbcheck/testrunner-duplicate-paths | 58 +++++++++++++++++++ 5 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 systemtests/tests/dbcheck/CMakeLists.txt create mode 100755 systemtests/tests/dbcheck/test-setup create mode 100755 systemtests/tests/dbcheck/testrunner-duplicate-paths diff --git a/systemtests/scripts/functions b/systemtests/scripts/functions index c384470a6b8..8b14673bc7e 100644 --- a/systemtests/scripts/functions +++ b/systemtests/scripts/functions @@ -558,7 +558,7 @@ run_headless_dbcheck() { print_debug "checking with ${BAREOS_DBCHECK_BINARY}" if test "$debug" -eq 1 ; then - "${BAREOS_DBCHECK_BINARY}" "${working_dir}" "${db_name}" "${db_user}" "${db_password}" --verbose -d 500 "$@" | tee "${tmp}/dbcheck.out" + "${BAREOS_DBCHECK_BINARY}" "${working_dir}" "${db_name}" "${db_user}" "${db_password}" --verbose -b -d 500 "$@" | tee "${tmp}/dbcheck.out" else "${BAREOS_DBCHECK_BINARY}" "${working_dir}" "${db_name}" "${db_user}" "${db_password}" -b "$@" >"${tmp}/dbcheck.out" 2>&1 fi diff --git a/systemtests/tests/CMakeLists.txt b/systemtests/tests/CMakeLists.txt index 84fe583325a..ed27b17493f 100644 --- a/systemtests/tests/CMakeLists.txt +++ b/systemtests/tests/CMakeLists.txt @@ -39,6 +39,7 @@ add_subdirectory(copy-migrate) add_subdirectory(copy-archive-job) add_subdirectory(copy-remote-bscan) add_subdirectory(dedupestimate) +add_subdirectory(dbcheck) add_subdirectory(deprecation) add_subdirectory(droplet-s3) add_subdirectory(encrypt-signature-no-tls) diff --git a/systemtests/tests/dbcheck/CMakeLists.txt b/systemtests/tests/dbcheck/CMakeLists.txt new file mode 100644 index 00000000000..393275d9165 --- /dev/null +++ b/systemtests/tests/dbcheck/CMakeLists.txt @@ -0,0 +1,21 @@ +# BAREOS® - Backup Archiving REcovery Open Sourced +# +# Copyright (C) 2024-2024 Bareos GmbH & Co. KG +# +# This program is Free Software; you can redistribute it and/or +# modify it under the terms of version three of the GNU Affero General Public +# License as published by the Free Software Foundation and included +# in the file LICENSE. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. + +get_filename_component(BASENAME ${CMAKE_CURRENT_BINARY_DIR} NAME) +create_systemtest(${SYSTEMTEST_PREFIX} ${BASENAME}) diff --git a/systemtests/tests/dbcheck/test-setup b/systemtests/tests/dbcheck/test-setup new file mode 100755 index 00000000000..d64e0e0081e --- /dev/null +++ b/systemtests/tests/dbcheck/test-setup @@ -0,0 +1,32 @@ +#!/bin/bash + +# BAREOS® - Backup Archiving REcovery Open Sourced +# +# Copyright (C) 2024-2024 Bareos GmbH & Co. KG +# +# This program is Free Software; you can redistribute it and/or +# modify it under the terms of version three of the GNU Affero General Public +# License as published by the Free Software Foundation and included +# in the file LICENSE. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. + +set -e +set -o pipefail +set -u + + +#shellcheck source=../environment.in +. ./environment + +#shellcheck source=../scripts/functions +. "${rscripts}"/functions +"${rscripts}"/cleanup diff --git a/systemtests/tests/dbcheck/testrunner-duplicate-paths b/systemtests/tests/dbcheck/testrunner-duplicate-paths new file mode 100755 index 00000000000..70342333b88 --- /dev/null +++ b/systemtests/tests/dbcheck/testrunner-duplicate-paths @@ -0,0 +1,58 @@ +#!/bin/bash + +# BAREOS® - Backup Archiving REcovery Open Sourced +# +# Copyright (C) 2024-2024 Bareos GmbH & Co. KG +# +# This program is Free Software; you can redistribute it and/or +# modify it under the terms of version three of the GNU Affero General Public +# License as published by the Free Software Foundation and included +# in the file LICENSE. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. + +set -e +set -o pipefail +set -u + +# +# Create duplicate path entries and remove them. +# + +TestName="$(basename "$(pwd)")" +export TestName + +#shellcheck source=../environment.in +. ./environment + +#shellcheck source=../scripts/functions +. "${rscripts}"/functions +# recreate the database, so we can start with a clean one +"${rscripts}"/setup + +start_test + +# we need to get rid of the uniqueness constraint first or we will not be able +# to add duplicate paths +# the easiest way to do this is to drop the index entirely +run_query "DROP INDEX path_name_idx" +run_query "INSERT INTO Path (path) VALUES ('x'), ('y'), ('x')" +run_query "SELECT * FROM Path" > "${tmp}/select_before.out" + +run_headless_dbcheck --fix + +run_query "SELECT * FROM Path" > "${tmp}/select_after.out" +run_query "WITH counted (path, count) AS (SELECT path, COUNT(*) FROM Path GROUP BY path) SELECT count FROM counted WHERE count > 1" > "${tmp}/after.out" + + +expect_grep "(0 rows)" "${tmp}/after.out" "Not all duplicates were removed." + +end_test