6
0
mirror of https://github.com/FirebirdSQL/firebird-qa.git synced 2025-01-22 21:43:06 +01:00
firebird-qa/tests/bugs/core_5201_test.py

63 lines
2.3 KiB
Python
Raw Normal View History

2021-04-26 20:07:00 +02:00
#coding:utf-8
2022-01-25 22:55:48 +01:00
"""
ID: issue-5482
ISSUE: 5482
TITLE: Return nonzero result code when restore fails on activating and creating deferred user index
DESCRIPTION:
According to Alex response on letter 25-apr-2016 19:15, zero retcode returned ONLY when restore
was done WITH '-verbose' switch, and this was fixed. When restoring was done without additional
switches, retcode was NON zero and its value was 1.
We create table with UNIQUE computed-by index which expression refers to other table (Firebird allows this!).
Because other table (test_2) initially is empty, index _can_ be created. But after this we insert record into
this table and do commit. Since that moment backup of this database will have table test_1 but its index will
NOT be able to restore (unless '-i' switch specified).
We will use this inability of restore index by checking 'gbak -rep -v ...' return code: it should be NON zero.
If code will skip exception then this will mean FAIL of test.
JIRA: CORE-5201
"""
2021-04-26 20:07:00 +02:00
import pytest
2021-11-30 19:13:50 +01:00
from pathlib import Path
2022-01-25 22:55:48 +01:00
from firebird.qa import *
2021-04-26 20:07:00 +02:00
2022-01-25 22:55:48 +01:00
init_script = """
2021-04-26 20:07:00 +02:00
create table test_1(x int);
create table test_2(x int);
insert into test_1 values(1);
insert into test_1 values(2);
insert into test_1 values(3);
commit;
create unique index test_1_unq on test_1 computed by( iif( exists(select * from test_2), 1, x ) );
commit;
insert into test_2 values(1000);
commit;
2021-11-30 19:13:50 +01:00
"""
2021-04-26 20:07:00 +02:00
2022-01-25 22:55:48 +01:00
db = db_factory(init=init_script)
2021-04-26 20:07:00 +02:00
2022-01-25 22:55:48 +01:00
act = python_act('db')
2021-04-26 20:07:00 +02:00
2022-01-25 22:55:48 +01:00
expected_stdout = """
2021-11-30 19:13:50 +01:00
gbak: ERROR:attempt to store duplicate value (visible to active transactions) in unique index "TEST_1_UNQ"
gbak: ERROR: Problematic key value is (<expression> = 1)
"""
2021-04-26 20:07:00 +02:00
2021-11-30 19:13:50 +01:00
fbk_file = temp_file('core_5201.fbk')
tmp_db_file = temp_file('tmp_core_5201.fdb')
2021-04-26 20:07:00 +02:00
2021-11-30 19:13:50 +01:00
@pytest.mark.version('>=3.0')
2022-01-25 22:55:48 +01:00
def test_1(act: Action, fbk_file: Path, tmp_db_file: Path):
with act.connect_server() as srv:
srv.database.backup(database=act.db.db_path, backup=fbk_file)
2021-11-30 19:13:50 +01:00
assert srv.readlines() == []
#
2022-01-25 22:55:48 +01:00
act.expected_stderr = 'We expect error'
act.expected_stdout = expected_stdout
act.gbak(switches=['-rep', '-v', str(fbk_file), str(tmp_db_file)])
2021-11-30 19:13:50 +01:00
# filter stdout
2022-01-25 22:55:48 +01:00
act.stdout = '\n'.join([line for line in act.stdout.splitlines() if ' ERROR:' in line])
assert act.return_code == 2
assert act.clean_stdout == act.clean_expected_stdout