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

207 lines
6.6 KiB
Python
Raw Normal View History

2021-04-26 20:07:00 +02:00
#coding:utf-8
2022-01-21 18:49:26 +01:00
"""
ID: issue-998
ISSUE: 998
TITLE: Extend maximum database page size to 32KB
DESCRIPTION:
We create DB with page_size = 32784, then add two table int it, both with UTF8 fields.
First table (test_non_coll) has field which is based on trivial text domain.
Second table (test_collated) has two 'domained' fields and both underlying domains are
based on two collations: case_insensitive and case_insensitive + accent_insensitive.
NOTE: we use MAXIMAL POSSIBLE length of every text field.
Then we add to both tables some text data in order to check then correctness of queries
which use several kinds of search (namely: starting with, like and between).
Then we make validation, backup, restore and run again DML query and validation.
Also, we do extraction of metadata before backup and after restore.
Finally, we:
1) check that all error logs are empty;
2) compare logs of DML, metadata extraction - they should be identical.
JIRA: CORE-2192
FBTEST: bugs.core_2192
2022-01-21 18:49:26 +01:00
"""
2021-04-26 20:07:00 +02:00
import pytest
2022-01-21 18:49:26 +01:00
from firebird.qa import *
from firebird.driver import SrvRestoreFlag
2021-11-12 18:29:54 +01:00
from io import BytesIO
2021-04-26 20:07:00 +02:00
2021-11-12 18:29:54 +01:00
test_size = 32768 # -- Ran 1 tests in 4.504s
# test_size = 16384 # -- Ran 1 tests in 2.735s
max_indx1 = int(test_size / 4 - 9)
max_indx6 = int(max_indx1 / 6)
max_indx8 = int(max_indx1 / 8)
2021-04-26 20:07:00 +02:00
2022-01-21 18:49:26 +01:00
init_script = f"""
2021-11-12 18:29:54 +01:00
set list on;
set bail on;
set echo on;
create sequence g;
commit;
create collation utf8_ci for utf8 from unicode case insensitive;
create collation utf8_ai_ci for utf8 from unicode accent insensitive case insensitive ;
commit;
create domain dm_non_coll as varchar({max_indx1});
create domain dm_collated_ci as varchar({max_indx6}) character set utf8 collate utf8_ci;
create domain dm_collated_ai_ci as varchar({max_indx6}) character set utf8 collate utf8_ai_ci;
commit;
recreate table test_non_coll(
txt_non_coll dm_non_coll
);
recreate table test_collated(
txt_ci dm_collated_ci
,txt_ai_ci dm_collated_ai_ci
);
commit;
create index test_non_coll on test_non_coll(txt_non_coll);
create index test_coll_ci on test_collated(txt_ci);
create index test_coll_ai_ci on test_collated(txt_ai_ci);
commit;
2021-12-22 20:23:11 +01:00
"""
2021-11-12 18:29:54 +01:00
2022-01-21 18:49:26 +01:00
db = db_factory(init=init_script, page_size=32784)
2021-04-26 20:07:00 +02:00
2022-01-21 18:49:26 +01:00
test_script = f'''
2021-11-12 18:29:54 +01:00
--show version;
delete from test_non_coll;
delete from test_collated;
commit;
set count on;
insert into test_non_coll(txt_non_coll)
select
rpad('', {max_indx1}, 'QWERTY' || gen_id(g,1) )
from
-- rdb$types rows 10000
(select 1 i from rdb$types rows 200), (select 1 i from rdb$types rows 5)
rows 361
;
commit;
2021-04-26 20:07:00 +02:00
2021-11-12 18:29:54 +01:00
insert into test_collated(txt_ci, txt_ai_ci)
select
rpad('', {max_indx6}, 'Ещё Съешь Этих Мягких Французских Булочек Да Выпей Же Чаю')
,rpad('', {max_indx6}, 'Ещё Французских Булочек Этих Мягких Съешь Да Чаю Выпей Же')
from
(select 1 i from rdb$types rows 250), (select 1 i from rdb$types rows 2)
;
commit;
set count off;
set list on;
set plan on;
select count(*)
from test_non_coll
where txt_non_coll starting with 'QWERTY'
union all
select count(*)
from test_collated
where txt_ci starting with 'еЩё'
union all
select count(*)
from test_collated
where txt_ai_ci starting with 'ёЩЕ'
union all
select count(*)
from test_collated
where txt_ci = lower(rpad('', {max_indx6}, 'Ещё Съешь Этих Мягких Французских Булочек Да Выпей Же Чаю'))
2021-04-26 20:07:00 +02:00
2021-11-12 18:29:54 +01:00
union all
2021-04-26 20:07:00 +02:00
2021-11-12 18:29:54 +01:00
select count(*)
from test_collated
where txt_ai_ci = rpad('', {max_indx6}, 'Ещё Французских Булочек Этих Мягких Съешь Да Чаю Выпей Же')
;
select count(*)
from test_non_coll
where txt_non_coll like 'QWERTY%%'
union all
select count(*)
from test_collated
where txt_ci like 'еЩё%%'
union all
select count(*)
from test_collated
where txt_ai_ci like 'ёЩЕ%%'
union all
select count(*)
from test_collated
where txt_ci between
rpad('', {max_indx6}, 'ещё Съешь ЭТИХ Мягких Французских Булочек Да Выпей Же Чаю')
and
rpad('', {max_indx6}, 'ЕЩЁ Съешь Этих МЯГКИХ фРанцузских Булочек Да Выпей Же Чаю')
union all
select count(*)
from test_collated
where txt_ai_ci between
rpad('', {max_indx6}, 'ёще фРанцузских Булочек Этих Мягких Съешь Да Чаю Выпёй Же')
and
rpad('', {max_indx6}, 'ёщё Французских Булочёк Этих Мягких Съёшь Да Чаю Выпёй Жё')
;
set plan off;
'''
2022-01-21 18:49:26 +01:00
act = python_act('db')
2021-11-12 18:29:54 +01:00
@pytest.mark.version('>=4.0')
2022-01-21 18:49:26 +01:00
def test_1(act: Action):
2021-11-12 18:29:54 +01:00
# 1. FIRST RUN DML_TEST
2022-01-21 18:49:26 +01:00
act.script = test_script
act.execute(charset='utf8')
run_dml_log_1 = act.stdout
2021-11-12 18:29:54 +01:00
# 2. EXTRACT METADATA-1
2022-01-21 18:49:26 +01:00
act.reset()
act.isql(switches=['-x'], charset='utf8')
extract_meta1_sql = act.stdout
2021-11-12 18:29:54 +01:00
# 3. VALIDATE DATABASE-1
# [pcisar] I don't understand the point of validation as the original test does not check
# that validation passed
2022-01-21 18:49:26 +01:00
with act.connect_server() as srv:
srv.database.validate(database=act.db.db_path)
2021-11-12 18:29:54 +01:00
validate_log_1 = srv.readlines()
# 4. TRY TO BACKUP AND RESTORE
2022-01-21 18:49:26 +01:00
with act.connect_server() as srv:
2021-11-12 18:29:54 +01:00
backup = BytesIO()
2022-01-21 18:49:26 +01:00
srv.database.local_backup(database=act.db.db_path, backup_stream=backup)
2021-11-12 18:29:54 +01:00
backup.seek(0)
2022-01-21 18:49:26 +01:00
srv.database.local_restore(backup_stream=backup, database=act.db.db_path,
2021-11-12 18:29:54 +01:00
flags=SrvRestoreFlag.REPLACE)
backup.close()
# 5. EXTRACT METADATA-2
2022-01-21 18:49:26 +01:00
act.reset()
act.isql(switches=['-x'], charset='utf8')
extract_meta2_sql = act.stdout
2021-11-12 18:29:54 +01:00
# 6. AGAIN RUN DML_TEST
2022-01-21 18:49:26 +01:00
act.reset()
act.script = test_script
act.execute(charset='utf8')
run_dml_log_2 = act.stdout
2021-11-12 18:29:54 +01:00
# 7. VALIDATE DATABASE-2
2022-01-21 18:49:26 +01:00
with act.connect_server() as srv:
srv.database.validate(database=act.db.db_path)
2021-11-12 18:29:54 +01:00
validate_log_2 = srv.readlines()
# 8. CHECKS
# 1) STDERR for: create DB, backup, restore, validation-1 and validation-2 - they all must be EMPTY.
# [pcisar] This is granted as exception would be raised if there would be any error
# 2) diff between dml_1.log and dml_2.log should be EMPTY.
assert run_dml_log_1 == run_dml_log_2
# 3) diff between meta1.log and meta2.log should be EMPTY.
assert extract_meta1_sql == extract_meta2_sql