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
|
2022-02-02 15:46:19 +01:00
|
|
|
FBTEST: bugs.core_5618
|
2022-01-25 22:55:48 +01:00
|
|
|
"""
|
2021-04-26 20:07:00 +02:00
|
|
|
|
|
|
|
import pytest
|
2021-12-09 19:26:42 +01:00
|
|
|
import zipfile
|
|
|
|
from difflib import unified_diff
|
|
|
|
from pathlib import Path
|
2022-01-25 22:55:48 +01:00
|
|
|
from firebird.qa import *
|
2021-12-09 19:26:42 +01:00
|
|
|
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-12-09 19:26:42 +01:00
|
|
|
"""
|
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
|
|
|
|
2021-12-09 19:26:42 +01: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())
|
2021-12-09 19:26:42 +01:00
|
|
|
#
|
2022-01-25 22:55:48 +01:00
|
|
|
with act.db.connect() as con:
|
2021-12-09 19:26:42 +01:00
|
|
|
c = con.cursor()
|
2022-01-25 22:55:48 +01:00
|
|
|
with open(blob_src, mode='rb') as blob_handle:
|
2021-12-09 19:26:42 +01:00
|
|
|
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()
|
2021-12-09 19:26:42 +01:00
|
|
|
# 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,
|
2021-12-09 19:26:42 +01:00
|
|
|
flags=SrvRepairFlag.FULL | SrvRepairFlag.VALIDATE_DB)
|
|
|
|
assert srv.readlines() == []
|
|
|
|
#
|
2022-01-25 22:55:48 +01:00
|
|
|
log_after = act.get_firebird_log()
|
2021-12-09 19:26:42 +01:00
|
|
|
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']
|