Skip to content

Commit

Permalink
Add tests to ensure cylc play / validate do not mess with Cylc 7 DB (
Browse files Browse the repository at this point in the history
  • Loading branch information
MetRonnie authored Jan 30, 2023
1 parent fd45cb5 commit f26b78c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
6 changes: 5 additions & 1 deletion tests/functional/database/07-incompatible.t
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@
# and that suitable error message is given.

. "$(dirname "$0")/test_header"
set_test_number 5
set_test_number 6

install_workflow
# install the cylc7 restart database
SRV_DIR="${WORKFLOW_RUN_DIR}/.service"
mkdir "$SRV_DIR"
sqlite3 "${SRV_DIR}/db" < 'db.sqlite3'
sqlite3 "${SRV_DIR}/db" '.tables' > orig_tables.txt

run_ok "${TEST_NAME_BASE}-validate" cylc validate "$WORKFLOW_NAME"

Expand All @@ -35,6 +36,9 @@ grep_ok \
'Workflow database is incompatible with Cylc .*, or is corrupted' \
"${TEST_NAME}.stderr"

# Check no new tables have been created
cmp_ok orig_tables.txt <<< "$(sqlite3 "${SRV_DIR}/db" '.tables')"

TEST_NAME="${TEST_NAME_BASE}-clean-fail"
run_fail "$TEST_NAME" cylc clean "$WORKFLOW_NAME"
grep_ok \
Expand Down
37 changes: 36 additions & 1 deletion tests/integration/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from pathlib import Path
import sqlite3
import pytest

from cylc.flow.exceptions import WorkflowConfigError
from cylc.flow.exceptions import ServiceFileError, WorkflowConfigError
from cylc.flow.parsec.exceptions import ListValueError
from cylc.flow.pathutil import get_workflow_run_pub_db_path


@pytest.mark.parametrize(
Expand Down Expand Up @@ -322,3 +325,35 @@ def test_queue_treated_as_comma_separated(flow, validate):
)
with pytest.raises(ListValueError, match="cannot contain a space"):
validate(reg)


def test_validate_incompatible_db(one_conf, flow, validate):
"""Validation should fail for an incompatible DB due to not being able
to load template vars."""
wid = flow(one_conf)
# Create fake outdated DB
db_file = Path(get_workflow_run_pub_db_path(wid))
db_file.parent.mkdir(parents=True, exist_ok=True)
db_file.touch()
conn = sqlite3.connect(db_file)
try:
conn.execute(
'CREATE TABLE suite_params(key TEXT, value TEXT, PRIMARY KEY(key))'
)
conn.commit()
finally:
conn.close()

with pytest.raises(
ServiceFileError, match="Workflow database is incompatible"
):
validate(wid)

# No tables should have been created
stmt = "SELECT name FROM sqlite_master WHERE type='table'"
conn = sqlite3.connect(db_file)
try:
tables = [i[0] for i in conn.execute(stmt)]
finally:
conn.close()
assert tables == ['suite_params']

0 comments on commit f26b78c

Please sign in to comment.