6
0
mirror of https://github.com/FirebirdSQL/firebird-qa.git synced 2025-02-02 02:40:42 +01:00

More python tests

This commit is contained in:
Pavel Císař 2021-11-30 19:13:50 +01:00
parent afcaf43049
commit f3d94d2873
8 changed files with 529 additions and 317 deletions

View File

@ -131,9 +131,9 @@ fdb_file_1 = temp_file('tmp_core_5078.fdb')
@pytest.mark.version('>=2.5.6')
def test_1(act_1: Action, fbk_file_1: Path, fdb_file_1: Path):
script_file = zipfile.Path(act_1.vars['files'] / 'core_5078.zip',
zipped_fbk_file = zipfile.Path(act_1.vars['files'] / 'core_5078.zip',
at='tmp_core_5078.fbk')
fbk_file_1.write_bytes(script_file.read_bytes())
fbk_file_1.write_bytes(zipped_fbk_file.read_bytes())
with act_1.connect_server() as srv:
srv.database.restore(database=str(fdb_file_1), backup=str(fbk_file_1))
srv.wait()

View File

@ -24,7 +24,8 @@
# qmid: None
import pytest
from firebird.qa import db_factory, isql_act, Action
from pathlib import Path
from firebird.qa import db_factory, python_act, Action, temp_file
# version: 2.5.6
# resources: None
@ -42,7 +43,7 @@ init_script_1 = """
commit;
insert into test_2 values(1000);
commit;
"""
"""
db_1 = db_factory(sql_dialect=3, init=init_script_1)
@ -142,17 +143,27 @@ db_1 = db_factory(sql_dialect=3, init=init_script_1)
# cleanup( (f_backup, f_restore, tmpbkp, tmpres) )
#
#---
#act_1 = python_act('db_1', test_script_1, substitutions=substitutions_1)
act_1 = python_act('db_1', substitutions=substitutions_1)
expected_stdout_1 = """
Restore finished with error code: 2
RESTORE LOG: gbak: ERROR:attempt to store duplicate value (visible to active transactions) in unique index "TEST_1_UNQ"
RESTORE LOG: gbak: ERROR: Problematic key value is (<expression> = 1)
"""
@pytest.mark.version('>=2.5.6')
@pytest.mark.xfail
def test_1(db_1):
pytest.fail("Test not IMPLEMENTED")
gbak: ERROR:attempt to store duplicate value (visible to active transactions) in unique index "TEST_1_UNQ"
gbak: ERROR: Problematic key value is (<expression> = 1)
"""
fbk_file = temp_file('core_5201.fbk')
tmp_db_file = temp_file('tmp_core_5201.fdb')
@pytest.mark.version('>=3.0')
def test_1(act_1: Action, fbk_file: Path, tmp_db_file: Path):
with act_1.connect_server() as srv:
srv.database.backup(database=str(act_1.db.db_path), backup=str(fbk_file))
assert srv.readlines() == []
#
act_1.expected_stderr = 'We expect error'
act_1.expected_stdout = expected_stdout_1
act_1.gbak(switches=['-rep', '-v', str(fbk_file), str(tmp_db_file)])
# filter stdout
act_1.stdout = '\n'.join([line for line in act_1.stdout.splitlines() if ' ERROR:' in line])
assert act_1.return_code == 2
assert act_1.clean_stdout == act_1.clean_expected_stdout

View File

@ -25,7 +25,9 @@
# qmid: None
import pytest
from firebird.qa import db_factory, isql_act, Action
import zipfile
from pathlib import Path
from firebird.qa import db_factory, python_act, Action, temp_file
# version: 3.0
# resources: None
@ -167,12 +169,27 @@ db_1 = db_factory(sql_dialect=3, init=init_script_1)
# cleanup( (f_restore,f_xmeta_log,f_xmeta_err,f_apply_log,f_apply_err,tmpbkp,tmpres) )
#
#---
#act_1 = python_act('db_1', test_script_1, substitutions=substitutions_1)
act_1 = python_act('db_1', substitutions=substitutions_1)
fbk_file_1 = temp_file('tmp_core_5207.fbk')
fdb_file_1 = temp_file('tmp_core_5207.fdb')
@pytest.mark.version('>=3.0')
@pytest.mark.xfail
def test_1(db_1):
pytest.fail("Test not IMPLEMENTED")
def test_1(act_1: Action, fbk_file_1: Path, fdb_file_1: Path, capsys):
zipped_fbk_file = zipfile.Path(act_1.vars['files'] / 'core_5207.zip',
at='core_5207.fbk')
fbk_file_1.write_bytes(zipped_fbk_file.read_bytes())
with act_1.connect_server() as srv:
srv.database.restore(database=str(fdb_file_1), backup=str(fbk_file_1))
srv.wait()
act_1.isql(switches=['-x', str(fdb_file_1)], connect_db=False)
metadata = act_1.stdout
# Check metadata
for line in metadata.splitlines():
if 'GRANT USAGE ON DOMAIN' in line:
pytest.fail(f'WRONG GRANT: {line}')
# Apply metadata to main test database
act_1.reset()
act_1.isql(switches=[], input=metadata)
assert act_1.clean_stdout == act_1.clean_expected_stdout

View File

@ -26,7 +26,9 @@
# qmid: None
import pytest
from firebird.qa import db_factory, isql_act, Action
from time import time
from threading import Timer
from firebird.qa import db_factory, python_act, Action
# version: 2.5.6
# resources: None
@ -44,7 +46,7 @@ init_script_1 = """
recreate table test(id int);
commit;
"""
"""
db_1 = db_factory(sql_dialect=3, init=init_script_1)
@ -111,7 +113,8 @@ db_1 = db_factory(sql_dialect=3, init=init_script_1)
# check_events(5)
#
#---
#act_1 = python_act('db_1', test_script_1, substitutions=substitutions_1)
act_1 = python_act('db_1', substitutions=substitutions_1)
expected_stdout_1 = """
{'dml_event': 1}
@ -128,11 +131,36 @@ expected_stdout_1 = """
{'dml_event': 1}
5: event was SUCCESSFULLY delivered.
"""
"""
def send_events(con, command_list):
cur = con.cursor()
for cmd in command_list:
cur.execute(cmd)
con.commit()
@pytest.mark.version('>=2.5.6')
@pytest.mark.xfail
def test_1(db_1):
pytest.fail("Test not IMPLEMENTED")
def test_1(act_1: Action, capsys):
def check_events(seqno: int):
with act_1.db.connect() as con:
timed_event = Timer(1.0, send_events, args=[con, ["insert into test(id) values (rand()*1000)",]])
with con.event_collector(['dml_event']) as events:
timed_event.start()
t1 = time()
max4delivering = 3
e = events.wait(max4delivering)
t2 = time()
print(e)
print(f'{seqno}: event was SUCCESSFULLY delivered.' if t2-t1 < max4delivering
else f'{seqno}: event was NOT delivered for {t2-t1}s (threshold is {max4delivering}s)')
#
check_events(1)
check_events(2)
check_events(3)
check_events(4)
check_events(5)
# Check
act_1.expected_stdout = expected_stdout_1
act_1.stdout = capsys.readouterr().out
assert act_1.clean_stdout == act_1.clean_expected_stdout

View File

@ -11,7 +11,7 @@
# qmid: None
import pytest
from firebird.qa import db_factory, isql_act, Action
from firebird.qa import db_factory, python_act, Action
# version: 2.5.6
# resources: None
@ -31,7 +31,7 @@ init_script_1 = """
references test( f01 )
-- ^-- this must be specified in 2.5.x
);
"""
"""
db_1 = db_factory(sql_dialect=3, init=init_script_1)
@ -115,20 +115,24 @@ db_1 = db_factory(sql_dialect=3, init=init_script_1)
#
#
#---
#act_1 = python_act('db_1', test_script_1, substitutions=substitutions_1)
act_1 = python_act('db_1', substitutions=substitutions_1)
expected_stdout_1 = """
EXTRACTED METADATA LOG: CREATE TABLE TEST (F01 INTEGER CONSTRAINT F01_NN NOT NULL,
EXTRACTED METADATA LOG: F02 INTEGER CONSTRAINT F02_NN NOT NULL,
EXTRACTED METADATA LOG: F03 INTEGER CONSTRAINT F03_NN NOT NULL,
EXTRACTED METADATA LOG: CONSTRAINT F01_PK PRIMARY KEY (F01),
EXTRACTED METADATA LOG: CONSTRAINT F02_UK UNIQUE (F02));
EXTRACTED METADATA LOG: ALTER TABLE TEST ADD CONSTRAINT F03_FK FOREIGN KEY (F03) REFERENCES TEST (F01);
"""
CREATE TABLE TEST (F01 INTEGER CONSTRAINT F01_NN NOT NULL,
F02 INTEGER CONSTRAINT F02_NN NOT NULL,
F03 INTEGER CONSTRAINT F03_NN NOT NULL,
CONSTRAINT F01_PK PRIMARY KEY (F01),
CONSTRAINT F02_UK UNIQUE (F02));
ALTER TABLE TEST ADD CONSTRAINT F03_FK FOREIGN KEY (F03) REFERENCES TEST (F01);
"""
@pytest.mark.version('>=2.5.6')
@pytest.mark.xfail
def test_1(db_1):
pytest.fail("Test not IMPLEMENTED")
def test_1(act_1: Action):
act_1.expected_stdout = expected_stdout_1
act_1.isql(switches=['-x'])
# filter stdout
act_1.stdout = '\n'.join([line for line in act_1.stdout.splitlines() if 'CONSTRAINT' in line])
assert act_1.clean_stdout == act_1.clean_expected_stdout

View File

@ -22,16 +22,24 @@
# qmid: None
import pytest
from firebird.qa import db_factory, isql_act, Action
from difflib import unified_diff
from firebird.qa import db_factory, python_act, Action
# version: 3.0
# resources: None
substitutions_1 = []
init_script_1 = """"""
init_script_1 = """
create collation "Циферки" for utf8 from unicode case insensitive 'NUMERIC-SORT=1';
create collation "Испания" for iso8859_1 from es_es_ci_ai 'SPECIALS-FIRST=1';;
commit;
create domain "Артикулы" varchar(12) character set utf8 collate "Циферки";
create domain "Комрады" varchar(40) character set iso8859_1 collate "Испания";
commit;
"""
db_1 = db_factory(sql_dialect=3, init=init_script_1)
db_1 = db_factory(sql_dialect=3, init=init_script_1, charset='UTF8')
# test_script_1
#---
@ -212,16 +220,51 @@ db_1 = db_factory(sql_dialect=3, init=init_script_1)
#
#
#---
#act_1 = python_act('db_1', test_script_1, substitutions=substitutions_1)
act_1 = python_act('db_1', substitutions=substitutions_1)
expected_stdout_1 = """
REMOVE METADATA LOG: Records affected: 0
REMOVE METADATA LOG: Records affected: 0
"""
Records affected: 0
Records affected: 0
"""
remove_metadata = """
drop domain "Комрады";
drop domain "Артикулы";
drop collation "Испания";
drop collation "Циферки";
commit;
set list on;
set count on;
select f.rdb$field_name
from rdb$fields f
where
f.rdb$system_flag is distinct from 1
and f.rdb$field_name not starting with upper('rdb$');
select r.rdb$collation_name
from rdb$collations r
where
r.rdb$system_flag is distinct from 1;
"""
@pytest.mark.version('>=3.0')
@pytest.mark.xfail
def test_1(db_1):
pytest.fail("Test not IMPLEMENTED")
def test_1(act_1: Action):
#
act_1.isql(switches=['-x'])
metadata = act_1.stdout
# Remove metadata
act_1.reset()
act_1.expected_stdout = expected_stdout_1
act_1.isql(switches=[], input=remove_metadata)
assert act_1.clean_stdout == act_1.clean_expected_stdout
# Apply metadata
act_1.reset()
act_1.isql(switches=[], input=metadata)
# Extract metadatata again
act_1.reset()
act_1.isql(switches=['-x'])
# Check metadata
meta_diff = list(unified_diff(metadata.splitlines(), act_1.stdout.splitlines()))
assert meta_diff == []

View File

@ -34,8 +34,14 @@
# versions: 3.0, 4.0
# qmid: None
from __future__ import annotations
from typing import List
import pytest
from firebird.qa import db_factory, isql_act, Action
import subprocess
import time
import re
from pathlib import Path
from firebird.qa import db_factory, python_act, Action, temp_files, temp_file
# version: 3.0
# resources: None
@ -94,7 +100,7 @@ init_script_1 = """
insert into gen_tab (id) values (0);
commit;
"""
"""
db_1 = db_factory(sql_dialect=3, init=init_script_1)
@ -212,14 +218,26 @@ db_1 = db_factory(sql_dialect=3, init=init_script_1)
# # + UNEXPECTED, LOG #2: -update conflicts with concurrent update
# # + UNEXPECTED, LOG #2: -concurrent transaction number is 32
# # + UNEXPECTED, LOG #2: -At procedure 'P_INCREMENT' line: 17, col: 17
# # + UNEXPECTED, LOG #2: After line 6 in file C:\\MIX
# irebird\\QA
# bt-repo mp mp_5222_run.sql
# # + UNEXPECTED, LOG #2: After line 6 in file C:\\MIX\\Firebird\\QA\\fbt-repo\\tmp\\tmp_5222_run.sql
# # EXPECTED, LOG #2: AFTER_PROC
#
#
#---
#act_1 = python_act('db_1', test_script_1, substitutions=substitutions_1)
act_1 = python_act('db_1', substitutions=substitutions_1)
test_script_1 = """
commit;
set list on;
set transaction read committed no record_version lock timeout 3;
select current_timestamp as before_proc
from rdb$database;
select * from p_increment(10);
select current_timestamp as after_proc
from rdb$database;
"""
expected_stdout_1 = """
EXPECTED, LOG #0: BEFORE_PROC
@ -239,13 +257,60 @@ expected_stdout_1 = """
EXPECTED, LOG #2: SELECTED_ID
EXPECTED, LOG #2: PROC_FINISH
EXPECTED, LOG #2: AFTER_PROC
"""
"""
@pytest.mark.version('>=3.0')
@pytest.mark.xfail
def test_1(db_1):
pytest.fail("Test not IMPLEMENTED")
PLANNED_DML_ATTACHMENTS = 3
run_sql = temp_file('core_5222_run.sql')
dml_logs_1 = temp_files([f'tmp_dml_5222_{i+1}' for i in range(PLANNED_DML_ATTACHMENTS)])
@pytest.mark.version('>=3.0,<4')
def test_1(act_1: Action, run_sql: Path, dml_logs_1: List[Path], capsys):
pattern = re.compile("BEFORE_PROC*|PROC_START*|SELECTED_ID*|PROC_FINISH*|AFTER_PROC*")
run_sql.write_text(test_script_1)
# Launching several concurrent child ISQL processes which perform `run_sql` script
f_logs = []
p_dml = []
try:
for dml_log in dml_logs_1: # Contains PLANNED_DML_ATTACHMENTS items
f = open(dml_log, mode='w')
f_logs.append(f)
p_dml.append(subprocess.Popen([act_1.vars['isql'],
'-i', str(run_sql),
'-user', act_1.db.user,
'-password', act_1.db.password,
act_1.db.dsn],
stdout=f, stderr=subprocess.STDOUT))
#
time.sleep(PLANNED_DML_ATTACHMENTS * 5)
finally:
for f in f_logs:
f.close()
for p in p_dml:
p.terminate()
#
# 1. Each log _should_ contain ONLY following lines:
# BEFORE_PROC 2016-05-03 09:27:57.6210
# PROC_START 2016-05-03 09:27:57.6210
# SELECTED_ID 1569
# PROC_FINISH 2016-05-03 09:28:04.0740
# AFTER_PROC 2016-05-03 09:28:04.0740
# 2. _NO_ log should contain 'SQLSTATE = 40001'
#
# Open every log and print 1st word from each line, ignoring values of timestamp and ID.
i = 0
for dml_log in dml_logs_1:
for line in dml_log.read_text().splitlines():
if line.split():
if pattern.match(line):
print(f'EXPECTED, LOG #{i}: {line.split()[0]}')
else:
print(f'UNEXPECTED, LOG #{i}: {line}')
i += 1
# Check
act_1.expected_stdout = expected_stdout_1
act_1.stdout = capsys.readouterr().out
assert act_1.clean_stdout == act_1.clean_expected_stdout
# version: 4.0
# resources: None
@ -265,8 +330,7 @@ db_2 = db_factory(sql_dialect=3, init=init_script_2)
@pytest.mark.version('>=4.0')
@pytest.mark.xfail
def test_2(db_2):
pytest.fail("Test not IMPLEMENTED")
pytest.skip("Requires changed firebird.conf [ReadConsistency=0]")

View File

@ -22,12 +22,13 @@
# qmid: None
import pytest
from firebird.qa import db_factory, isql_act, Action
from pathlib import Path
from firebird.qa import db_factory, python_act, Action, temp_file
# version: 3.0
# resources: None
substitutions_1 = []
substitutions_1 = [('^O.*', '')]
init_script_1 = """"""
@ -153,12 +154,56 @@ db_1 = db_factory(sql_dialect=3, init=init_script_1)
#
#
#---
#act_1 = python_act('db_1', test_script_1, substitutions=substitutions_1)
act_1 = python_act('db_1', substitutions=substitutions_1)
SP_ARGS_COUNT = 5000
ddl_script = temp_file('core_5231.sql')
def build_script(ddl_script: Path):
with open(ddl_script, 'w') as ddl_file:
ddl_file.write("""
set term ^;
execute block as
begin
execute statement 'drop procedure sp_test';
when any do begin end
end ^
commit ^
create or alter procedure sp_test returns (
""")
delimiter = ''
for i in range(SP_ARGS_COUNT):
ddl_file.write(f'{delimiter}o{i} int')
delimiter = ','
ddl_file.write(
""") as begin
for execute statement 'select
""")
delimiter = ''
for i in range(SP_ARGS_COUNT):
ddl_file.write(f'{delimiter}{i}')
delimiter = ','
ddl_file.write(" from rdb$database'\ninto ")
delimiter = ''
for i in range(SP_ARGS_COUNT):
ddl_file.write(f'{delimiter}o{i}')
delimiter = ','
ddl_file.write("""
do suspend;
end^
set term ;^
commit;
set list on;
select * from sp_test;
""")
@pytest.mark.version('>=3.0')
@pytest.mark.xfail
def test_1(db_1):
pytest.fail("Test not IMPLEMENTED")
def test_1(act_1: Action, ddl_script: Path):
build_script(ddl_script)
act_1.isql(switches=[], input_file=ddl_script, charset='NONE')
assert act_1.clean_stdout == act_1.clean_expected_stdout