6
0
mirror of https://github.com/FirebirdSQL/firebird-qa.git synced 2025-01-22 13:33:07 +01:00
firebird-qa/tests/bugs/core_5843_test.py

207 lines
5.7 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-6104
ISSUE: 6104
TITLE: Wrong handling of failures of TRANSACTION START trigger
DESCRIPTION:
JIRA: CORE-5843
FBTEST: bugs.core_5843
NOTES:
[25.11.2023] pzotov
Writing code requires more care since 6.0.0.150: ISQL does not allow specifying duplicate delimiters without any statements between them (two semicolon, two carets etc).
2022-01-26 21:10:46 +01:00
"""
2021-04-26 20:07:00 +02:00
2022-01-26 21:10:46 +01:00
import pytest
from firebird.qa import *
2021-04-26 20:07:00 +02:00
2022-01-26 21:10:46 +01:00
substitutions = [('line[:]{0,1}[\\s]+[\\d]+.*', 'line'),
('transaction[\\s]+[\\d]+[\\s]+aborted', 'transaction aborted'),
('tx=[\\d]+', 'tx='), ('TX_ID[\\s]+[\\d]+', 'TX_ID'),
('exception[\\s]+[\\d]+.*', 'exception')]
2021-04-26 20:07:00 +02:00
2022-01-26 21:10:46 +01:00
init_script = """
2021-04-26 20:07:00 +02:00
--set echo on;
set bail on;
create or alter trigger tx_rollback on transaction rollback as begin end;
create or alter trigger tx_start on transaction start as begin end;
create or alter trigger tx_commit on transaction commit as begin end;
create or alter view v_mon as
2022-01-26 21:10:46 +01:00
select
2021-04-26 20:07:00 +02:00
t.mon$transaction_id as tx_id
,t.mon$state as tx_state
--,a.mon$remote_process att_process
--,a.mon$attachment_name as att_name
--,a.mon$system_flag as att_sysflag
--,a.mon$user as att_user
from mon$transactions t
join mon$attachments a using (mon$attachment_id)
where mon$attachment_id = current_connection
;
commit;
set term ^;
create or alter exception ex_tra_start 'transaction @1 aborted'
^
create or alter procedure tx_trig_log(msg varchar(255))
as
declare s varchar(255);
begin
s = rdb$get_context('USER_SESSION', 'tx_trig_log');
2022-01-26 21:10:46 +01:00
if (s <> '') then
begin
2021-04-26 20:07:00 +02:00
s = s || ASCII_CHAR(10) || trim(msg) || ', current tx=' || current_transaction;
rdb$set_context('USER_SESSION', 'tx_trig_log', :s);
end
end
^
create or alter trigger tx_start on transaction start as
declare s varchar(255);
begin
execute procedure tx_trig_log('trigger on transaction start ');
2022-01-26 21:10:46 +01:00
if (rdb$get_context('USER_SESSION', 'tx_abort') = 1) then
2021-04-26 20:07:00 +02:00
begin
execute procedure tx_trig_log('exception on tx start ');
rdb$set_context('USER_SESSION', 'tx_abort', 0);
exception ex_tra_start using (current_transaction);
end
end
^
create or alter trigger tx_commit on transaction commit as
declare s varchar(255);
begin
execute procedure tx_trig_log('trigger on commit');
end
^
create or alter trigger tx_rollback on transaction rollback as
declare s varchar(255);
begin
execute procedure tx_trig_log('trigger on rollback');
end
^
create or alter procedure sp_use_atx as
begin
rdb$set_context('USER_SESSION', 'tx_abort', 1);
2022-01-26 21:10:46 +01:00
execute procedure tx_trig_log('sp_use_atx, point_a');
2021-04-26 20:07:00 +02:00
in autonomous transaction do
execute procedure tx_trig_log('sp_use_atx, point_b');
end
^
set term ;^
commit;
2021-12-22 20:23:11 +01:00
"""
2021-04-26 20:07:00 +02:00
2022-01-26 21:10:46 +01:00
db = db_factory(init=init_script)
2021-04-26 20:07:00 +02:00
2022-01-26 21:10:46 +01:00
test_script = """
2021-04-26 20:07:00 +02:00
set autoddl off;
set list on;
commit;
select 'test_1, point-1' as msg, v.* from rdb$database cross join v_mon v;
set term ^;
execute block as
declare c int;
begin
c = rdb$set_context('USER_SESSION', 'tx_abort', 1); -- flag to raise error on next tx start
end
^
set term ;^
2021-04-26 20:07:00 +02:00
commit;
select 'test_1, point-2' as msg, v.* from rdb$database cross join v_mon v; -- it start transaction
commit;
set count on;
select 'test_1, point-3' as msg, v.* from rdb$database cross join v_mon v;
set count off;
rollback;
-------------------------------------------------------------
--connect '$(DSN)' user 'SYSDBA' password 'masterkey';
set term ^;
execute block as
declare c int;
begin
c = rdb$set_context('USER_SESSION', 'tx_trig_log', ascii_char(10) || 'start: tx=' || current_transaction ); -- start logging
end
^
set term ;^
2021-04-26 20:07:00 +02:00
commit;
select 'test2, point-a' as msg, v.* from rdb$database cross join v_mon v;
execute procedure sp_use_atx;
/*
Statement failed, SQLSTATE = HY000
exception 3
-EX_TRA_START
-transaction 692 aborted
-At trigger 'TX_START' line: 10, col: 5
At procedure 'sp_use_atx' line: 4, col: 3
*/
select rdb$get_context('USER_SESSION', 'tx_trig_log') from rdb$database;
2021-12-22 20:23:11 +01:00
"""
2021-04-26 20:07:00 +02:00
2022-01-26 21:10:46 +01:00
act = isql_act('db', test_script, substitutions=substitutions)
2021-04-26 20:07:00 +02:00
2022-01-26 21:10:46 +01:00
expected_stdout = """
2021-04-26 20:07:00 +02:00
MSG test_1, point-1
TX_ID 22
TX_STATE 1
MSG test_1, point-3
TX_ID 25
TX_STATE 1
Records affected: 1
MSG test2, point-a
TX_ID 28
TX_STATE 1
RDB$GET_CONTEXT
start: tx=26
trigger on commit, current tx=26
trigger on transaction start, current tx=28
sp_use_atx, point_a, current tx=28
trigger on transaction start, current tx=29
exception on tx start, current tx=29
2021-12-22 20:23:11 +01:00
"""
2022-01-26 21:10:46 +01:00
expected_stderr = """
2021-04-26 20:07:00 +02:00
Statement failed, SQLSTATE = HY000
exception 1
-EX_TRA_START
-transaction 23 aborted
-At trigger 'TX_START' line
Statement failed, SQLSTATE = HY000
exception 1
-EX_TRA_START
-transaction 29 aborted
-At trigger 'TX_START' line
At procedure 'SP_USE_ATX' line
2021-12-22 20:23:11 +01:00
"""
2021-04-26 20:07:00 +02:00
@pytest.mark.version('>=3.0.4')
2022-01-26 21:10:46 +01:00
def test_1(act: Action):
act.expected_stdout = expected_stdout
act.expected_stderr = expected_stderr
act.execute()
assert (act.clean_stderr == act.clean_expected_stderr and
act.clean_stdout == act.clean_expected_stdout)