6
0
mirror of https://github.com/FirebirdSQL/firebird-qa.git synced 2025-01-23 05:53:06 +01:00
firebird-qa/tests/bugs/core_3598_test.py

105 lines
3.7 KiB
Python
Raw Normal View History

2021-04-26 20:07:00 +02:00
#coding:utf-8
2022-01-22 21:59:15 +01:00
"""
ID: issue-3952
ISSUE: 3952
TITLE: TRACE: add statistics of actions that were after transaction finished
DESCRIPTION:
Three tables are created: permanent, GTT with on commit PRESERVE rows and on commit DELETE rows.
2021-04-26 20:07:00 +02:00
2022-01-22 21:59:15 +01:00
Trace config is created with *prohibition* of any activity related to security<N>.fdb
but allow to log transactions-related events (commits and rollbacks) for working database.
Trace is started before furthe actions.
2021-04-26 20:07:00 +02:00
2022-01-22 21:59:15 +01:00
Then we launch ISQL and apply two DML for each of these tables:
1) insert row + commit;
2) insert row + rollback.
Finally (after ISQL will finish), we stop trace and parse its log.
For *each* table TWO lines with performance statristics must exist: both for COMMIT and ROLLBACK events.
JIRA: CORE-3598
FBTEST: bugs.core_3598
2022-01-22 21:59:15 +01:00
"""
2021-04-26 20:07:00 +02:00
2022-01-22 21:59:15 +01:00
import pytest
from firebird.qa import *
init_script = """
2021-04-26 20:07:00 +02:00
recreate table tfix(id int);
recreate global temporary table gtt_ssn(id int) on commit preserve rows;
recreate global temporary table gtt_tra(id int) on commit delete rows;
2021-11-17 19:43:06 +01:00
"""
2021-04-26 20:07:00 +02:00
2022-01-22 21:59:15 +01:00
db = db_factory(init=init_script)
2021-11-17 19:43:06 +01:00
2022-01-22 21:59:15 +01:00
act = python_act('db')
2021-11-17 19:43:06 +01:00
2022-01-22 21:59:15 +01:00
test_script = """
2021-11-17 19:43:06 +01:00
set autoddl off;
set echo on;
set count on;
set bail on;
insert into tfix(id) values(1);
commit;
insert into tfix(id) values(2);
rollback;
insert into gtt_ssn(id) values(1);
commit;
insert into gtt_ssn(id) values(2);
rollback;
insert into gtt_tra(id) values(1);
commit;
insert into gtt_tra(id) values(2);
rollback;
"""
2021-04-26 20:07:00 +02:00
2022-01-22 21:59:15 +01:00
expected_stdout = """
2021-11-17 19:43:06 +01:00
Statement statistics detected for COMMIT
2021-04-26 20:07:00 +02:00
Statement statistics detected for COMMIT
Statement statistics detected for ROLLBACK
Found performance block header
Found table statistics for TFIX
Statement statistics detected for COMMIT
Statement statistics detected for ROLLBACK
Found performance block header
Found table statistics for GTT_SSN
Statement statistics detected for COMMIT
Statement statistics detected for ROLLBACK
2021-11-17 19:43:06 +01:00
"""
2022-01-22 21:59:15 +01:00
trace = ['log_transactions = true',
'print_perf = true',
'log_initfini = false',
]
2021-04-26 20:07:00 +02:00
@pytest.mark.version('>=3.0')
2022-01-22 21:59:15 +01:00
def test_1(act: Action, capsys):
with act.trace(db_events=trace):
act.isql(switches=[], input=test_script)
2021-11-17 19:43:06 +01:00
# Output log of trace session, with filtering only interested info:
# Performance header text (all excessive spaces will be removed before comparison - see below):
perf_header='Table Natural Index Update Insert Delete Backout Purge Expunge'
checked_events= {') COMMIT_TRANSACTION': 'commit',
') ROLLBACK_TRANSACTION': 'rollback',
') EXECUTE_STATEMENT': 'execute_statement',
') START_TRANSACTION': 'start_transaction'
}
i, k = 0, 0
watched_event = ''
2022-01-22 21:59:15 +01:00
for line in act.trace_log:
2021-11-17 19:43:06 +01:00
k += 1
e = ''.join([v.upper() for x, v in checked_events.items() if x in line])
watched_event = e if e else watched_event
2021-04-26 20:07:00 +02:00
2021-11-17 19:43:06 +01:00
if ' ms,' in line and ('fetch' in line or 'mark' in line): # One of these *always* must be in trace statistics.
print(f'Statement statistics detected for {watched_event}')
i += 1
if ' '.join(line.split()).upper() == ' '.join(perf_header.split()).upper():
print('Found performance block header')
if line.startswith('TFIX') or line.startswith('GTT_SSN') or line.startswith('GTT_TRA'):
print(f'Found table statistics for {line.split()[0]}')
# Check
2022-01-22 21:59:15 +01:00
act.expected_stdout = expected_stdout
act.stdout = capsys.readouterr().out
assert act.clean_stdout == act.clean_expected_stdout