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

61 lines
2.1 KiB
Python
Raw Permalink Normal View History

2021-04-26 20:07:00 +02:00
#coding:utf-8
2022-01-25 22:55:48 +01:00
"""
ID: issue-5884
ISSUE: 5884
TITLE: Part of the pages of the second level blobs is not released when deleting relations
DESCRIPTION:
We create table with blob field and write into it binary data with length that
is too big to store such blob as level-0 and level-1. Filling is implemented as
specified in:
http://pythonhosted.org/fdb/differences-from-kdb.html#stream-blobs
Then we drop table and close connection.
Finally, we obtain firebird.log, run full validation (like 'gfix -v -full' does) and get firebird.log again.
Comparison of two firebird.log versions should give only one difference related to warnings, and they count
must be equal to 0.
JIRA: CORE-5618
FBTEST: bugs.core_5618
2022-01-25 22:55:48 +01:00
"""
2021-04-26 20:07:00 +02:00
import pytest
import zipfile
from difflib import unified_diff
from pathlib import Path
2022-01-25 22:55:48 +01:00
from firebird.qa import *
from firebird.driver import SrvRepairFlag
2021-04-26 20:07:00 +02:00
2022-01-25 22:55:48 +01:00
init_script = """
2021-04-26 20:07:00 +02:00
recreate table test(b blob sub_type 0);
"""
2021-04-26 20:07:00 +02:00
2022-01-25 22:55:48 +01:00
db = db_factory(init=init_script)
2021-04-26 20:07:00 +02:00
2022-01-25 22:55:48 +01:00
act = python_act('db')
2021-04-26 20:07:00 +02:00
2022-01-25 22:55:48 +01:00
blob_src = temp_file('core_5618.bin')
2021-04-26 20:07:00 +02:00
@pytest.mark.version('>=3.0.3')
2022-01-25 22:55:48 +01:00
def test_1(act: Action, blob_src: Path):
zipped_blob_file = zipfile.Path(act.files_dir / 'core_5618.zip', at='core_5618.bin')
blob_src.write_bytes(zipped_blob_file.read_bytes())
#
2022-01-25 22:55:48 +01:00
with act.db.connect() as con:
c = con.cursor()
2022-01-25 22:55:48 +01:00
with open(blob_src, mode='rb') as blob_handle:
c.execute('insert into test (b) values (?)', [blob_handle])
c.close()
con.execute_immediate('drop table test')
con.commit()
#
2022-01-25 22:55:48 +01:00
log_before = act.get_firebird_log()
# Run full validation (this is what 'gfix -v -full' does)
2022-01-25 22:55:48 +01:00
with act.connect_server() as srv:
srv.database.repair(database=act.db.db_path,
flags=SrvRepairFlag.FULL | SrvRepairFlag.VALIDATE_DB)
assert srv.readlines() == []
#
2022-01-25 22:55:48 +01:00
log_after = act.get_firebird_log()
log_diff = [line.strip().upper() for line in unified_diff(log_before, log_after)
if line.startswith('+') and 'WARNING' in line.upper()]
assert log_diff == ['+\tVALIDATION FINISHED: 0 ERRORS, 0 WARNINGS, 0 FIXED']