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

106 lines
3.5 KiB
Python
Raw Normal View History

2021-04-26 20:07:00 +02:00
#coding:utf-8
2022-01-24 20:27:02 +01:00
"""
ID: issue-5151
ISSUE: 5151
TITLE: Online validation during DML activity in other connection leads to message
"Error while trying to read from file" and "page in use during flush (210), file: cch.cpp line: 2672"
2022-01-24 20:27:02 +01:00
DESCRIPTION:
JIRA: CORE-4855
FBTEST: bugs.core_4855
2022-01-24 20:27:02 +01:00
"""
2021-04-26 20:07:00 +02:00
import pytest
2021-11-26 19:20:43 +01:00
import subprocess
import time
from pathlib import Path
2022-01-24 20:27:02 +01:00
from firebird.qa import *
2021-04-26 20:07:00 +02:00
2022-01-24 20:27:02 +01:00
substitutions = [('[0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9]', ''),
('Relation [0-9]{3,4}', 'Relation'),
('Statement failed, SQLSTATE = HY008', ''),
('operation was cancelled', ''), ('After line .*', '')]
2021-04-26 20:07:00 +02:00
2022-01-24 20:27:02 +01:00
db = db_factory()
2021-04-26 20:07:00 +02:00
2022-01-24 20:27:02 +01:00
act = python_act('db', substitutions=substitutions)
2021-04-26 20:07:00 +02:00
2022-01-24 20:27:02 +01:00
expected_stdout = """
2021-04-26 20:07:00 +02:00
Iteration #1:
21:16:28.31 Validation started
21:16:28.31 Relation 128 (TEST)
21:16:29.31 Acquire relation lock failed
21:16:29.31 Relation 128 (TEST) : 1 ERRORS found
21:16:30.04 Relation 129 (STOP)
21:16:30.04 process pointer page 0 of 1
21:16:30.04 Relation 129 (STOP) is ok
21:16:30.04 Validation finished
Iteration #2:
21:16:32.46 Validation started
21:16:32.46 Relation 128 (TEST)
21:16:33.46 Acquire relation lock failed
21:16:33.46 Relation 128 (TEST) : 1 ERRORS found
21:16:35.09 Relation 129 (STOP)
21:16:35.09 process pointer page 0 of 1
21:16:35.09 Relation 129 (STOP) is ok
21:16:35.09 Validation finished
2021-11-26 19:20:43 +01:00
INSERTED_ROWS OK, LOT OF.
"""
2021-04-26 20:07:00 +02:00
2022-01-24 20:27:02 +01:00
heavy_script = """
recreate sequence g;
recreate table test(id int, s varchar( 36 ) unique using index test_s_unq);
recreate table stop(id int);
commit;
set list on;
set transaction read committed;
set term ^;
execute block returns( inserted_rows varchar(20) ) as
begin
while ( not exists(select * from stop) ) do
begin
insert into test(id, s) values( gen_id(g,1), rpad('', 36, uuid_to_char(gen_uuid())) );
end
inserted_rows = iif(gen_id(g,0) > 0, 'OK, LOT OF.', 'FAIL: ZERO!');
suspend;
end
^
set term ;^
commit;
"""
heavy_script_file = temp_file('heavy_script.sql')
heavy_output = temp_file('heavy_script.out')
2021-04-26 20:07:00 +02:00
2021-11-26 19:20:43 +01:00
@pytest.mark.version('>=3.0')
2022-01-24 20:27:02 +01:00
def test_1(act: Action, heavy_script_file: Path, heavy_output: Path, capsys):
2021-11-26 19:20:43 +01:00
# Preparing script for ISQL that will do 'heavy DML'
2022-01-24 20:27:02 +01:00
heavy_script_file.write_text(heavy_script)
with open(heavy_output, mode='w') as heavy_out:
p_heavy_sql = subprocess.Popen([act.vars['isql'], '-i', str(heavy_script_file),
'-user', act.db.user,
'-password', act.db.password, act.db.dsn],
2021-11-26 19:20:43 +01:00
stdout=heavy_out, stderr=subprocess.STDOUT)
try:
time.sleep(4)
# Run validation twice
2022-01-24 20:27:02 +01:00
with act.connect_server() as srv:
2021-11-26 19:20:43 +01:00
print('Iteration #1:')
2022-01-24 20:27:02 +01:00
srv.database.validate(database=act.db.db_path, lock_timeout=1,
2021-11-26 19:20:43 +01:00
callback=print)
print('Iteration #2:')
2022-01-24 20:27:02 +01:00
srv.database.validate(database=act.db.db_path, lock_timeout=1,
2021-11-26 19:20:43 +01:00
callback=print)
# Stopping ISQL that is doing now 'heavy DML' (bulk-inserts):
2022-01-24 20:27:02 +01:00
act.isql(switches=[], input='insert into stop(id) values(1); commit;')
2021-11-26 19:20:43 +01:00
finally:
p_heavy_sql.terminate()
#
2022-01-24 20:27:02 +01:00
print(heavy_output.read_text())
2021-11-26 19:20:43 +01:00
# Check
2022-01-24 20:27:02 +01:00
act.reset()
act.expected_stdout = expected_stdout
act.stdout = capsys.readouterr().out
assert act.clean_stdout == act.clean_expected_stdout
2021-04-26 20:07:00 +02:00