2021-04-26 20:07:00 +02:00
#coding:utf-8
2022-01-27 20:08:36 +01:00
"""
ID : issue - 6508
ISSUE : 6508
TITLE : Deleting records from MON $ ATTACHMENTS using ORDER BY clause doesn ' t close the corresponding attachments
DESCRIPTION :
JIRA : CORE - 6266
2022-02-02 15:46:19 +01:00
FBTEST : bugs . core_6266
2022-01-27 20:08:36 +01:00
"""
2021-04-26 20:07:00 +02:00
import pytest
2021-12-14 20:56:34 +01:00
import time
2022-01-27 20:08:36 +01:00
from firebird . qa import *
2021-12-14 20:56:34 +01:00
from firebird . driver import DatabaseError
2021-04-26 20:07:00 +02:00
2022-01-27 20:08:36 +01:00
db = db_factory ( )
2021-12-14 20:56:34 +01:00
2022-01-27 20:08:36 +01:00
act = python_act ( ' db ' )
2021-04-26 20:07:00 +02:00
2022-01-27 20:08:36 +01:00
expected_stdout = """
2021-12-14 20:56:34 +01:00
Number of attachments that remains alive : 0
"""
2021-04-26 20:07:00 +02:00
@pytest.mark.version ( ' >=3.0 ' )
2022-01-27 20:08:36 +01:00
def test_1 ( act : Action , capsys ) :
2021-12-14 20:56:34 +01:00
ATT_CNT = 5
ATT_DELAY = 1
#
con_list = [ ]
for i in range ( ATT_CNT ) :
if i > 0 :
time . sleep ( ATT_DELAY )
2022-01-27 20:08:36 +01:00
con_list . append ( act . db . connect ( ) )
2021-12-14 20:56:34 +01:00
con_admin = con_list [ 0 ]
# This DOES NOT remove all attachments (only 'last' in order of timestamp), but
# DELETE statement must NOT contain phrase 'mon$attachment_id != current_connection':
con_admin . execute_immediate ( ' delete from mon$attachments where mon$system_flag is distinct from 1 order by mon$timestamp ' )
con_admin . commit ( )
#
cur_admin = con_admin . cursor ( )
cur_admin . execute ( ' select mon$attachment_id,mon$user from mon$attachments where mon$system_flag is distinct from 1 and mon$attachment_id != current_connection ' )
i = 0
for r in cur_admin :
print ( ' STILL ALIVE ATTACHMENT DETECTED: ' , r [ 0 ] , r [ 1 ] . strip ( ) )
i + = 1
print ( f ' Number of attachments that remains alive: { i } ' )
for con in con_list :
try :
con . close ( )
except DatabaseError :
pass
# Check
2022-01-27 20:08:36 +01:00
act . expected_stdout = expected_stdout
act . stdout = capsys . readouterr ( ) . out
assert act . clean_stdout == act . clean_expected_stdout