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:
|
2023-02-07 12:08:48 +01:00
|
|
|
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 is performed without additional switches then retcode is 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.
|
2022-01-25 22:55:48 +01:00
|
|
|
JIRA: CORE-5201
|
2022-02-02 15:46:19 +01:00
|
|
|
FBTEST: bugs.core_5201
|
2023-02-07 12:08:48 +01:00
|
|
|
NOTES:
|
|
|
|
[07.02.2023] pzotov
|
|
|
|
Adjusted tail of restore log: added messages
|
|
|
|
gbak: ERROR:Database is not online due to failure to activate one or more indices.
|
|
|
|
gbak: ERROR: Run gfix -online to bring database online without active indices.
|
|
|
|
(actual since 5.0.0.932; will be soon also for FB 3.x and 4.x - see letter from Alex, 07.02.2023 11:53).
|
2022-01-25 22:55:48 +01:00
|
|
|
"""
|
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 *
|
2023-02-07 12:08:48 +01:00
|
|
|
import re
|
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
|
|
|
|
2023-02-07 12:08:48 +01:00
|
|
|
gbak_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)
|
2023-02-07 12:08:48 +01:00
|
|
|
gbak: ERROR:Database is not online due to failure to activate one or more indices.
|
|
|
|
gbak: ERROR: Run gfix -online to bring database online without active indices.
|
2021-11-30 19:13:50 +01:00
|
|
|
"""
|
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() == []
|
|
|
|
#
|
2023-02-07 12:08:48 +01:00
|
|
|
act.expected_stdout = gbak_expected_stdout
|
|
|
|
act.gbak(switches=['-rep', '-v', str(fbk_file), str(tmp_db_file)], combine_output = True)
|
|
|
|
p_gbak_err = re.compile('^gbak:\s?ERROR:', re.IGNORECASE)
|
|
|
|
|
2021-11-30 19:13:50 +01:00
|
|
|
# filter stdout
|
2023-02-07 12:08:48 +01:00
|
|
|
act.stdout = '\n'.join([line for line in act.stdout.splitlines() if p_gbak_err.search(line)])
|
2022-01-25 22:55:48 +01:00
|
|
|
assert act.return_code == 2
|
|
|
|
assert act.clean_stdout == act.clean_expected_stdout
|