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_5704_test.py

106 lines
3.4 KiB
Python
Raw Normal View History

2021-04-26 20:07:00 +02:00
#coding:utf-8
2022-01-26 21:10:46 +01:00
"""
ID: issue-5970
ISSUE: 5970
TITLE: Avoid UPDATE of RDB$DATABASE by ALTER DATABASE statement when possible
DESCRIPTION:
Instead of doing 'nbackup -L' plus fill database with lot of new data and then 'nbackup -N' with waiting for
delta will be integrated into main file, we can get the same result by invoking 'alter database add difference file'
statement in the 1st attachment in RC NO_REC_VERS and WITHOUT COMMITTING it, and then attempt to establish new connect
using ES/EDS. Second attachment should be made without any problem, despite that transaction in 1st connect not yet
committed or rolled back.
Confirmed lock of rdb$database record (which leads to inability to establish new connect) on WI-V3.0.3.32837.
JIRA: CORE-5704
FBTEST: bugs.core_5704
2022-01-26 21:10:46 +01:00
"""
2021-04-26 20:07:00 +02:00
import pytest
import subprocess
import time
from pathlib import Path
2022-01-26 21:10:46 +01:00
from firebird.qa import *
from firebird.driver import ShutdownMode, ShutdownMethod
2021-04-26 20:07:00 +02:00
2022-01-26 21:10:46 +01:00
db = db_factory()
2022-01-26 21:10:46 +01:00
act = python_act('db')
2021-04-26 20:07:00 +02:00
2022-01-26 21:10:46 +01:00
expected_stdout = """
CHECK_EDS_RESULT 1
Records affected: 1
Records affected: 0
CHECK_EDS_RESULT 1
Records affected: 1
Records affected: 0
"""
eds_script = temp_file('eds_script.sql')
eds_output = temp_file('eds_script.out')
new_diff_file = temp_file('_new_diff_5704.tmp')
new_main_file = temp_file('new_main_5704.tmp')
2021-04-26 20:07:00 +02:00
@pytest.mark.version('>=3.0.3')
2022-01-26 21:10:46 +01:00
def test_1(act: Action, eds_script: Path, eds_output: Path, new_diff_file: Path,
new_main_file: Path):
eds_script.write_text(f"""
set count on;
set list on;
set autoddl off;
set term ^;
create or alter procedure sp_connect returns(check_eds_result int) as
declare usr varchar(31);
declare pwd varchar(31);
declare v_sttm varchar(255) = 'select 1 from rdb$database';
begin
2022-01-26 21:10:46 +01:00
usr ='{act.db.user}';
pwd = '{act.db.password}';
execute statement v_sttm
on external 'localhost:' || rdb$get_context('SYSTEM','DB_NAME')
as user usr password pwd
into check_eds_result;
suspend;
end
^
set term ^;
commit;
set transaction read committed no record_version lock timeout 1;
alter database add difference file '{new_diff_file}';
select * from sp_connect;
rollback;
select * from rdb$files;
rollback;
2021-04-26 20:07:00 +02:00
set transaction read committed no record_version lock timeout 1;
2021-04-26 20:07:00 +02:00
alter database add file '{new_main_file}';
select * from sp_connect;
--select * from rdb$files;
rollback;
select * from rdb$files;
""")
#
with open(eds_output, mode='w') as eds_out:
2022-01-26 21:10:46 +01:00
p_eds_sql = subprocess.Popen([act.vars['isql'], '-i', str(eds_script),
'-user', act.db.user,
'-password', act.db.password, act.db.dsn],
stdout=eds_out, stderr=subprocess.STDOUT)
try:
time.sleep(4)
finally:
p_eds_sql.terminate()
# Ensure that database is not busy
2022-01-26 21:10:46 +01:00
with act.connect_server() as srv:
srv.database.shutdown(database=act.db.db_path, mode=ShutdownMode.FULL,
method=ShutdownMethod.FORCED, timeout=0)
2022-01-26 21:10:46 +01:00
srv.database.bring_online(database=act.db.db_path)
# Check
2022-01-26 21:10:46 +01:00
act.expected_stdout = expected_stdout
act.stdout = eds_output.read_text()
assert act.clean_stdout == act.clean_expected_stdout