6
0
mirror of https://github.com/FirebirdSQL/firebird-qa.git synced 2025-01-22 21:43:06 +01:00
firebird-qa/tests/bugs/core_3732_test.py

188 lines
5.5 KiB
Python
Raw Normal View History

2021-04-26 20:07:00 +02:00
#coding:utf-8
#
# id: bugs.core_3732
# title: Segfault when closing attachment to database
2021-11-17 19:43:06 +01:00
# decription:
2021-04-26 20:07:00 +02:00
# Confirmed bug on: WI-V2.5.1.26351. Works fine on WI-V2.5.2.26540
# On 2.5.1:
# 1) test finished with:
# ERROR: bugs.core_3732
# Test cleanup: Exception raised while dropping database.
# FAILED (errors=1)
# 2) firebird.log did contain:
2021-11-17 19:43:06 +01:00
# REMOTE INTERFACE/gds__detach: Unsuccesful detach from database.
2021-04-26 20:07:00 +02:00
# Uncommitted work may have been lost
2021-11-17 19:43:06 +01:00
#
2021-04-26 20:07:00 +02:00
# tracker_id: CORE-3732
# min_versions: ['2.5.2']
# versions: 2.5.2
# qmid: None
import pytest
2021-11-17 19:43:06 +01:00
from difflib import unified_diff
from firebird.qa import db_factory, python_act, Action
2021-04-26 20:07:00 +02:00
# version: 2.5.2
# resources: None
2021-11-17 19:43:06 +01:00
substitutions_1 = [('STATEMENT FAILED, SQLSTATE = HY000', ''),
('RECORD NOT FOUND FOR USER: TMP\\$C3732', ''),
('AFTER LINE.*', '')]
2021-04-26 20:07:00 +02:00
init_script_1 = """"""
db_1 = db_factory(sql_dialect=3, init=init_script_1)
# test_script_1
#---
# import os
# import sys
# import subprocess
# import time
# import difflib
2021-11-17 19:43:06 +01:00
#
2021-04-26 20:07:00 +02:00
# os.environ["ISC_USER"] = user_name
# os.environ["ISC_PASSWORD"] = user_password
2021-11-17 19:43:06 +01:00
#
2021-04-26 20:07:00 +02:00
# # Obtain engine version:
# engine = str(db_conn.engine_version) # convert to text because 'float' object has no attribute 'startswith'
# db_file = db_conn.database_name
# db_conn.close()
2021-11-17 19:43:06 +01:00
#
2021-04-26 20:07:00 +02:00
# #---------------------------------------------
2021-11-17 19:43:06 +01:00
#
2021-04-26 20:07:00 +02:00
# def flush_and_close(file_handle):
# # https://docs.python.org/2/library/os.html#os.fsync
2021-11-17 19:43:06 +01:00
# # If you're starting with a Python file object f,
# # first do f.flush(), and
2021-04-26 20:07:00 +02:00
# # then do os.fsync(f.fileno()), to ensure that all internal buffers associated with f are written to disk.
# global os
2021-11-17 19:43:06 +01:00
#
2021-04-26 20:07:00 +02:00
# file_handle.flush()
# if file_handle.mode not in ('r', 'rb'):
# # otherwise: "OSError: [Errno 9] Bad file descriptor"!
# os.fsync(file_handle.fileno())
# file_handle.close()
2021-11-17 19:43:06 +01:00
#
2021-04-26 20:07:00 +02:00
# #--------------------------------------------
2021-11-17 19:43:06 +01:00
#
2021-04-26 20:07:00 +02:00
# def cleanup( f_names_list ):
# global os
# for i in range(len( f_names_list )):
# if os.path.isfile( f_names_list[i]):
# os.remove( f_names_list[i] )
# if os.path.isfile( f_names_list[i]):
# print('ERROR: can not remove file ' + f_names_list[i])
2021-11-17 19:43:06 +01:00
#
2021-04-26 20:07:00 +02:00
# #--------------------------------------------
2021-11-17 19:43:06 +01:00
#
2021-04-26 20:07:00 +02:00
# def svc_get_fb_log( engine, f_fb_log ):
2021-11-17 19:43:06 +01:00
#
2021-04-26 20:07:00 +02:00
# import subprocess
2021-11-17 19:43:06 +01:00
#
2021-04-26 20:07:00 +02:00
# if engine.startswith('2.5'):
# get_firebird_log_key='action_get_ib_log'
# else:
# get_firebird_log_key='action_get_fb_log'
2021-11-17 19:43:06 +01:00
#
2021-04-26 20:07:00 +02:00
# subprocess.call([ context['fbsvcmgr_path'],
# "localhost:service_mgr",
# get_firebird_log_key
# ],
# stdout=f_fb_log, stderr=subprocess.STDOUT
# )
2021-11-17 19:43:06 +01:00
#
2021-04-26 20:07:00 +02:00
# return
2021-11-17 19:43:06 +01:00
#
2021-04-26 20:07:00 +02:00
# #--------------------------------------------
2021-11-17 19:43:06 +01:00
#
2021-04-26 20:07:00 +02:00
# f_fblog_before=open( os.path.join(context['temp_directory'],'tmp_3732_fblog_before.txt'), 'w')
# svc_get_fb_log( engine, f_fblog_before )
# flush_and_close( f_fblog_before )
2021-11-17 19:43:06 +01:00
#
2021-04-26 20:07:00 +02:00
# sql_ddl='''
# drop user tmp$c3732;
# commit;
# create role REPL_ADMIN;
# create user tmp$c3732 password '12345';
# grant repl_admin to tmp$c3732;
# revoke all on all from tmp$c3732;
# drop user tmp$c3732;
2021-11-17 19:43:06 +01:00
# exit;
2021-04-26 20:07:00 +02:00
# '''
2021-11-17 19:43:06 +01:00
#
2021-04-26 20:07:00 +02:00
# f_ddl_sql = open( os.path.join(context['temp_directory'],'tmp_ddl_3732.sql'), 'w')
# f_ddl_sql.write(sql_ddl)
# flush_and_close( f_ddl_sql )
2021-11-17 19:43:06 +01:00
#
2021-04-26 20:07:00 +02:00
# f_ddl_log = open( os.path.join(context['temp_directory'],'tmp_ddl_3732.log'), 'w')
# subprocess.call( [ context['isql_path'], dsn, "-q", "-i",f_ddl_sql.name ],
# stdout=f_ddl_log,
# stderr=subprocess.STDOUT
# )
# flush_and_close( f_ddl_log )
2021-11-17 19:43:06 +01:00
#
2021-04-26 20:07:00 +02:00
# f_fblog_after=open( os.path.join(context['temp_directory'],'tmp_3732_fblog_after.txt'), 'w')
# svc_get_fb_log( engine, f_fblog_after )
# flush_and_close( f_fblog_after )
2021-11-17 19:43:06 +01:00
#
2021-04-26 20:07:00 +02:00
# # Now we can compare two versions of firebird.log and check their difference.
2021-11-17 19:43:06 +01:00
#
2021-04-26 20:07:00 +02:00
# oldfb=open(f_fblog_before.name, 'r')
# newfb=open(f_fblog_after.name, 'r')
2021-11-17 19:43:06 +01:00
#
2021-04-26 20:07:00 +02:00
# difftext = ''.join(difflib.unified_diff(
2021-11-17 19:43:06 +01:00
# oldfb.readlines(),
2021-04-26 20:07:00 +02:00
# newfb.readlines()
# ))
# oldfb.close()
# newfb.close()
2021-11-17 19:43:06 +01:00
#
2021-04-26 20:07:00 +02:00
# f_diff_txt=open( os.path.join(context['temp_directory'],'tmp_3732_diff.txt'), 'w')
# f_diff_txt.write(difftext)
# flush_and_close( f_diff_txt )
2021-11-17 19:43:06 +01:00
#
2021-04-26 20:07:00 +02:00
# # This should be empty:
# #######################
# with open( f_diff_txt.name,'r') as f:
# for line in f:
# print( line.upper() )
2021-11-17 19:43:06 +01:00
#
2021-04-26 20:07:00 +02:00
# # This should be empty:
# #######################
# with open( f_ddl_log.name,'r') as f:
# for line in f:
# print(line.upper())
2021-11-17 19:43:06 +01:00
#
2021-04-26 20:07:00 +02:00
# # CLEANUP
# #########
# time.sleep(1)
# cleanup( [i.name for i in (f_fblog_before, f_ddl_sql, f_ddl_log, f_fblog_after, f_diff_txt) ] )
2021-11-17 19:43:06 +01:00
#
#
2021-04-26 20:07:00 +02:00
#---
2021-11-17 19:43:06 +01:00
act_1 = python_act('db_1', substitutions=substitutions_1)
2021-04-26 20:07:00 +02:00
2021-11-17 19:43:06 +01:00
test_script_1 = """
create role REPL_ADMIN;
create user tmp$c3732 password '12345';
grant repl_admin to tmp$c3732;
revoke all on all from tmp$c3732;
drop user tmp$c3732;
drop role REPL_ADMIN;
exit;
"""
2021-04-26 20:07:00 +02:00
2021-11-17 19:43:06 +01:00
@pytest.mark.version('>=2.5.2')
def test_1(act_1: Action):
with act_1.connect_server() as srv:
srv.info.get_log()
log_before = srv.readlines()
act_1.isql(switches=['-q'], input=test_script_1)
with act_1.connect_server() as srv:
srv.info.get_log()
log_after = srv.readlines()
assert list(unified_diff(log_before, log_after)) == []
2021-04-26 20:07:00 +02:00