6
0
mirror of https://github.com/FirebirdSQL/firebird-qa.git synced 2025-01-23 14:03:06 +01:00
firebird-qa/tests/bugs/core_5907_test.py
2021-12-10 19:50:31 +01:00

266 lines
8.8 KiB
Python

#coding:utf-8
#
# id: bugs.core_5907
# title: Regression: can not launch trace if its 'database' section contains regexp pattern with curvy brackets to enclose quantifier
# decription:
# Database file name for check: {core_5907.97}.tmp // NB: outer curvy brackets ARE INCLUDED in this name.
# This name should match to pattern: (\\{core_5907.[[:DIGIT:]]{2}\\}).tmp -- but we have to duplicate every "{" and "}".
# Also, we have to duplicate '' otherwise it will be escaped by fbtest framework.
# Checked on 4.0.0.1224: OK, 14.047s.
#
# tracker_id: CORE-5907
# min_versions: ['4.0']
# versions: 4.0
# qmid: None
import pytest
from firebird.qa import db_factory, python_act, Action
# version: 4.0
# resources: None
substitutions_1 = [('.*{CORE_5907.97}.FDB', '{CORE_5907.97}.FDB'),
('.*{core_5907.97}.fdb', '{CORE_5907.97}.FDB')]
init_script_1 = """
recreate table test(id int);
commit;
"""
db_1 = db_factory(sql_dialect=3, init=init_script_1, filename='{core_5907.97}.fdb')
# test_script_1
#---
#
# import os
# import re
# import subprocess
# import time
# import shutil
# from fdb import services
# from subprocess import Popen
#
# os.environ["ISC_USER"] = user_name
# os.environ["ISC_PASSWORD"] = user_password
#
# this_fdb = db_conn.database_name
# test_fdb = os.path.join( os.path.split(this_fdb)[0], "{core_5907.97}.tmp") # name of copy will be: %FBT_REPO%\\tmp\\{core_5907.97}.tmp
#
# db_conn.close()
#
# #--------------------------------------------
#
# def flush_and_close( file_handle ):
# # https://docs.python.org/2/library/os.html#os.fsync
# # If you're starting with a Python file object f,
# # first do f.flush(), and
# # then do os.fsync(f.fileno()), to ensure that all internal buffers associated with f are written to disk.
# global os
#
# file_handle.flush()
# if file_handle.mode not in ('r', 'rb') and file_handle.name != os.devnull:
# # otherwise: "OSError: [Errno 9] Bad file descriptor"!
# os.fsync(file_handle.fileno())
# file_handle.close()
#
# #--------------------------------------------
#
# def cleanup( f_names_list ):
# global os
# for i in range(len( f_names_list )):
# if type(f_names_list[i]) == file:
# del_name = f_names_list[i].name
# elif type(f_names_list[i]) == str:
# del_name = f_names_list[i]
# else:
# print('Unrecognized type of element:', f_names_list[i], ' - can not be treated as file.')
# del_name = None
#
# if del_name and os.path.isfile( del_name ):
# os.remove( del_name )
#
# #--------------------------------------------
#
# txt30 = '''# Trace config, format for 3.0. Generated auto, do not edit!
# database=(%[\\\\\\\\/](\\{{core_5907.[[:DIGIT:]]{{2}}\\}}).tmp)
# {
# enabled = true
# time_threshold = 0
# #log_statement_finish = true
# log_connections = true
# }
# '''
#
# f_trc_cfg=open( os.path.join(context['temp_directory'],'tmp_trace_5907.cfg'), 'w')
# f_trc_cfg.write(txt30)
# flush_and_close( f_trc_cfg )
#
# shutil.copy2( this_fdb, test_fdb )
#
# # ##############################################################
# # S T A R T T R A C E i n S E P A R A T E P R O C E S S
# # ##############################################################
#
# f_trc_log=open( os.path.join(context['temp_directory'],'tmp_trace_5907.log'), "w")
# f_trc_err=open( os.path.join(context['temp_directory'],'tmp_trace_5907.err'), "w")
#
# p_trace = Popen( [ context['fbsvcmgr_path'],
# 'localhost:service_mgr',
# 'action_trace_start',
# 'trc_cfg', f_trc_cfg.name
# ],
# stdout = f_trc_log, stderr = f_trc_err
# )
#
# # this delay need for trace start and finish its output about invalid section in its config file:
# time.sleep(1)
#
# # ####################################################
# # G E T A C T I V E T R A C E S E S S I O N I D
# # ####################################################
# # Save active trace session info into file for further parsing it and obtain session_id back (for stop):
#
# f_trc_lst = open( os.path.join(context['temp_directory'],'tmp_trace_5907.lst'), 'w')
# subprocess.call( [ context['fbsvcmgr_path'],
# 'localhost:service_mgr',
# 'action_trace_list'
# ],
# stdout=f_trc_lst
# )
# flush_and_close( f_trc_lst )
#
# # !!! DO NOT REMOVE THIS LINE !!!
# #time.sleep(3)
#
# trcssn=0
# with open( f_trc_lst.name,'r') as f:
# for line in f:
# i=1
# if 'Session ID' in line:
# for word in line.split():
# if i==3:
# trcssn=word
# i=i+1
# break
# # Result: `trcssn` is ID of active trace session. Now we have to terminate it:
# #.............................................................................
#
# #sql_cmd="insert into extdecimal(dec34_34) values (1)"
#
# sql_cmd='select mon$database_name from mon$database'
#
# con1=fdb.connect(dsn = 'localhost:' + test_fdb)
# cur=con1.cursor()
# try:
# cur.execute( sql_cmd )
# for r in cur:
# print( r[0] )
# except Exception,e:
# for i in e[0].split('\\n'):
# print('CLIENT GOT ERROR:',i)
# finally:
# cur.close()
#
# con1.close()
# #.............................................................................
#
# time.sleep(1)
#
# # ####################################################
# # S E N D R E Q U E S T T R A C E T O S T O P
# # ####################################################
# if trcssn>0:
# fn_nul = open(os.devnull, 'w')
# #f_trc_log=open( os.path.join(context['temp_directory'],'tmp_trace_5907.log'), "w")
# subprocess.call( [ context['fbsvcmgr_path'],
# 'localhost:service_mgr',
# 'action_trace_stop','trc_id', trcssn
# ],
# stdout=fn_nul
# )
# fn_nul.close()
# # DO NOT REMOVE THIS LINE:
# time.sleep(1)
#
#
# p_trace.terminate()
#
# flush_and_close( f_trc_log )
# flush_and_close( f_trc_err )
#
# # 1. Trace STDERR log should be EMPTY:
# ######################################
#
# # Example of STDERR when wrong database name pattern is spesified:
# # Trace session ID 11 started
# # Error creating trace session for database "":
# # Passed text: illegal line <database=(%[\\/]({core_5907.[[:DIGIT:]]{2}}).tmp)>
#
# f_list = ( f_trc_err, )
# for i in range(len(f_list)):
# f_name=f_list[i].name
# if os.path.getsize(f_name) > 0:
# with open( f_name,'r') as f:
# for line in f:
# print("Unexpected STDERR, file "+f_name+": "+line)
#
# # 2. Trace STDOUT log must contain one ATTACH and one DETACH events, e.g:
# #########################################################################
# # 2018-09-26T09:42:26.7340 (508:02122400) ATTACH_DATABASE
# # C:\\MIX\\FIREBIRD\\QA\\FBT-REPO\\TMP\\{CORE_5907.97}.TMP (ATT_10, SYSDBA:NONE, NONE, TCPv4:127.0.0.1/4159)
# # C:\\Python27\\python.exe:2080
# # 2018-09-26T09:42:26.7500 (508:02122400) DETACH_DATABASE
# # C:\\MIX\\FIREBIRD\\QA\\FBT-REPO\\TMP\\{CORE_5907.97}.TMP (ATT_10, SYSDBA:NONE, NONE, TCPv4:127.0.0.1/4159)
# # C:\\Python27\\python.exe:2080
#
# msg='Found expected '
# with open( f_trc_log.name,'r') as f:
# for line in f:
# if 'ATTACH_DATABASE' in line:
# print( msg + 'ATTACH.')
# if 'DETACH_DATABASE' in line:
# print( msg + 'DETACH.')
#
#
# # CLEANUP
# #########
# time.sleep(1)
# cleanup( (f_trc_cfg, f_trc_log, f_trc_err, f_trc_lst, test_fdb) )
#
#
#---
act_1 = python_act('db_1', substitutions=substitutions_1)
expected_stdout_1 = """
{CORE_5907.97}.FDB
Found expected ATTACH.
Found expected DETACH.
"""
trace_conf = ['database=(%[\\\\/](\\{{core_5907.[[:DIGIT:]]{{2}}\\}}).fdb)',
'{',
'enabled = true',
'time_threshold = 0',
'log_connections = true',
'log_initfini = false',
'}'
]
@pytest.mark.version('>=4.0')
def test_1(act_1: Action, capsys):
with act_1.trace(config=trace_conf):
act_1.isql(switches=[],
input='set list on;select mon$database_name from mon$database;')
print(act_1.stdout)
#
for line in act_1.trace_log:
if 'ATTACH_DATABASE' in line:
print('Found expected ATTACH.')
if 'DETACH_DATABASE' in line:
print('Found expected DETACH.')
# Check
act_1.expected_stdout = expected_stdout_1
act_1.stdout = capsys.readouterr().out
assert act_1.clean_stdout == act_1.clean_expected_stdout