2021-04-26 20:07:00 +02:00
|
|
|
#coding:utf-8
|
2022-01-21 18:49:26 +01:00
|
|
|
|
|
|
|
"""
|
|
|
|
ID: issue-3072
|
|
|
|
ISSUE: 3072
|
|
|
|
TITLE: Write note into log when automatic sweep is started
|
|
|
|
DESCRIPTION:
|
|
|
|
JIRA: CORE-2668
|
2022-02-02 15:46:19 +01:00
|
|
|
FBTEST: bugs.core_2668
|
2022-01-21 18:49:26 +01:00
|
|
|
"""
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2024-11-07 14:15:14 +01:00
|
|
|
import pytest
|
2021-11-16 19:44:53 +01:00
|
|
|
import time
|
|
|
|
import subprocess
|
|
|
|
import re
|
|
|
|
from pathlib import Path
|
|
|
|
from difflib import unified_diff
|
2022-01-21 18:49:26 +01:00
|
|
|
from firebird.qa import *
|
2024-11-07 14:15:14 +01:00
|
|
|
from firebird.driver import DbWriteMode, ShutdownMode, ShutdownMethod
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-21 18:49:26 +01:00
|
|
|
db = db_factory()
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2024-11-07 14:15:14 +01:00
|
|
|
act = python_act('db')
|
2021-11-16 19:44:53 +01:00
|
|
|
|
2024-11-07 14:15:14 +01:00
|
|
|
test_script = """
|
|
|
|
recreate table test(s varchar(36) unique);
|
|
|
|
insert into test(s) values('LOCKED_FOR_PAUSE');
|
|
|
|
commit;
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2024-11-07 14:15:14 +01:00
|
|
|
set transaction read committed WAIT;
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2024-11-07 14:15:14 +01:00
|
|
|
update test set s = s where s = 'LOCKED_FOR_PAUSE';
|
2021-11-16 19:44:53 +01:00
|
|
|
|
2024-11-07 14:15:14 +01:00
|
|
|
set term ^;
|
|
|
|
execute block as
|
|
|
|
declare n int = 150;
|
|
|
|
declare v_role varchar(31);
|
|
|
|
begin
|
|
|
|
while (n > 0) do
|
|
|
|
in autonomous transaction do
|
|
|
|
insert into test(s) values( rpad('', 36, uuid_to_char(gen_uuid()) ) )
|
|
|
|
returning :n-1 into n;
|
2021-11-16 19:44:53 +01:00
|
|
|
|
2024-11-07 14:15:14 +01:00
|
|
|
v_role = left(replace( uuid_to_char(gen_uuid()), '-', ''), 31);
|
2021-11-16 19:44:53 +01:00
|
|
|
|
2024-11-07 14:15:14 +01:00
|
|
|
begin
|
|
|
|
execute statement ('update test set s = s where s = ?') ('LOCKED_FOR_PAUSE')
|
|
|
|
on external
|
|
|
|
'localhost:' || rdb$get_context('SYSTEM', 'DB_NAME')
|
|
|
|
as user 'SYSDBA' password 'masterkey' role v_role
|
|
|
|
with autonomous transaction;
|
|
|
|
when any do
|
2021-11-16 19:44:53 +01:00
|
|
|
begin
|
2024-11-07 14:15:14 +01:00
|
|
|
end
|
|
|
|
end
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2024-11-07 14:15:14 +01:00
|
|
|
end
|
|
|
|
^
|
|
|
|
set term ;^
|
|
|
|
set heading off;
|
|
|
|
select '-- shutdown me now --' from rdb$database;
|
|
|
|
"""
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2024-11-07 14:15:14 +01:00
|
|
|
tmp_script = temp_file('work_script.sql')
|
2022-01-21 18:49:26 +01:00
|
|
|
|
2024-11-07 14:15:14 +01:00
|
|
|
@pytest.mark.es_eds
|
|
|
|
@pytest.mark.version('>=3')
|
|
|
|
def test_1(act: Action, tmp_script: Path):
|
|
|
|
tmp_script.write_text(test_script)
|
2022-01-21 18:49:26 +01:00
|
|
|
with act.connect_server() as srv:
|
2024-11-07 14:15:14 +01:00
|
|
|
srv.database.set_sweep_interval(database=act.db.db_path, interval=100)
|
2022-01-21 18:49:26 +01:00
|
|
|
srv.database.set_write_mode(database=act.db.db_path, mode=DbWriteMode.ASYNC)
|
2024-11-07 14:15:14 +01:00
|
|
|
p_work_sql = subprocess.Popen([act.vars['isql'], '-i', str(tmp_script),
|
|
|
|
'-user', act.db.user,
|
|
|
|
'-password', act.db.password, act.db.dsn],
|
|
|
|
stderr = subprocess.STDOUT)
|
|
|
|
time.sleep(3)
|
|
|
|
try:
|
|
|
|
srv.database.shutdown(database=act.db.db_path, mode=ShutdownMode.FULL,
|
|
|
|
method=ShutdownMethod.FORCED, timeout=0)
|
|
|
|
finally:
|
|
|
|
p_work_sql.terminate()
|
2022-01-21 18:49:26 +01:00
|
|
|
srv.database.bring_online(database=act.db.db_path)
|
2024-11-07 14:15:14 +01:00
|
|
|
srv.info.get_log()
|
|
|
|
fblog_before = srv.readlines()
|
2022-01-21 18:49:26 +01:00
|
|
|
with act.db.connect() as con_for_sweep_start:
|
2024-11-07 14:15:14 +01:00
|
|
|
con_for_sweep_start.begin()
|
2021-11-16 19:44:53 +01:00
|
|
|
time.sleep(2)
|
2024-11-07 14:15:14 +01:00
|
|
|
srv.info.get_log()
|
|
|
|
fblog_after = srv.readlines()
|
|
|
|
pattern = re.compile('Sweep\\s+.*SWEEPER', re.IGNORECASE)
|
|
|
|
success = False
|
|
|
|
for line in unified_diff(fblog_before, fblog_after):
|
|
|
|
if line.startswith('+') and pattern.search(line):
|
|
|
|
success = True
|
|
|
|
assert success
|