6
0
mirror of https://github.com/FirebirdSQL/firebird-qa.git synced 2025-02-02 10:50:42 +01:00
firebird-qa/tests/bugs/core_5477_test.py

186 lines
6.0 KiB
Python
Raw Normal View History

2021-04-26 20:07:00 +02:00
#coding:utf-8
2022-01-25 22:55:48 +01:00
"""
ID: issue-5747
ISSUE: 5747
TITLE: Trace duplicates asci_char(13) in its output (Windows only)
DESCRIPTION:
We launch trace and create connect to DB with statement line 'select 1 from rdb$database'.
Trace log should contain several lines related to connection, transaction and statement.
These lines should be separated by standard Windows PAIR of characters: CR + NL.
Count of these chars should be equal (ideally; actually 1st line in trace has EOL = single NL
rather than pair CR+NL).
We then open trace log as binary file and read all its content into dict of Counter type,
thus we can get number of occurences for each character, including CR and NL.
Finally, we compare number of occurences of CR and NL. Difference has to be no more than 1.
JIRA: CORE-5477
"""
2021-04-26 20:07:00 +02:00
import pytest
2022-01-25 22:55:48 +01:00
from firebird.qa import *
2021-04-26 20:07:00 +02:00
2022-01-25 22:55:48 +01:00
db = db_factory()
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
expected_stdout = """
EXPECTED.
"""
2021-04-26 20:07:00 +02:00
2022-01-25 22:55:48 +01:00
@pytest.mark.skip('FIXME: Not IMPLEMENTED')
@pytest.mark.version('>=3')
@pytest.mark.platform('Windows')
def test_1(act: Action):
pytest.fail("Not IMPLEMENTED")
2021-04-26 20:07:00 +02:00
# test_script_1
#---
#
2021-04-26 20:07:00 +02:00
# import os
# import subprocess
# import time
# from fdb import services
# from subprocess import Popen
# from collections import Counter
#
2021-04-26 20:07:00 +02:00
# os.environ["ISC_USER"] = user_name
# os.environ["ISC_PASSWORD"] = user_password
#
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'
#
2021-04-26 20:07:00 +02:00
# db_conn.close()
#
# # NB, 06.12.2016: as of fdb 1.6.1 one need to EXPLICITLY specify user+password pair when doing connect
2021-04-26 20:07:00 +02:00
# # via to FB services API by services.connect() - see FB tracker, PYFB-69
# # ("Can not connect to FB services if set ISC_USER & ISC_PASSWORD by os.environ[ ... ]")
#
2021-04-26 20:07:00 +02:00
# fb_home = services.connect(host='localhost', user= user_name, password= user_password).get_home_directory()
# # fb_home = services.connect(host='localhost').get_home_directory()
#
2021-04-26 20:07:00 +02:00
# if engine.startswith('2.5'):
# fb_home = fb_home + 'bin'+os.sep
# txt = '''# Generated auto, do not edit!
# <database %[\\\\\\\\/]security?.fdb>
# enabled false
# </database>
#
2021-04-26 20:07:00 +02:00
# <database %[\\\\\\\\/]bugs.core_5477.fdb>
# enabled true
# time_threshold 0
# log_initfini false
# log_connections true
# log_transactions true
# log_statement_finish = true
# </database>
# '''
# else:
# txt = '''# Generated auto, do not edit!
# database=%[\\\\\\\\/]security?.fdb
# {
# enabled = false
# }
# database=%[\\\\\\\\/]bugs.core_5477.fdb
# {
# enabled = true
# time_threshold = 0
# log_initfini = false
# log_connections = true
# log_transactions = true
# log_statement_finish = true
# }
# '''
# f_trc_cfg=open( os.path.join(context['temp_directory'],'tmp_trc_5477.cfg'), 'w')
# f_trc_cfg.write(txt)
# f_trc_cfg.close()
#
2021-04-26 20:07:00 +02:00
# # ##############################################################
# # 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
# # ##############################################################
#
2021-04-26 20:07:00 +02:00
# f_trc_log=open( os.path.join(context['temp_directory'],'tmp_trc_5477.log'), "w")
# f_trc_err=open( os.path.join(context['temp_directory'],'tmp_trc_5477.err'), "w")
#
2021-04-26 20:07:00 +02:00
# p_trace = Popen( [ fb_home+'fbsvcmgr', 'localhost:service_mgr', 'action_trace_start' , 'trc_cfg', f_trc_cfg.name],stdout=f_trc_log,stderr=f_trc_err)
#
2021-04-26 20:07:00 +02:00
# time.sleep(1)
#
2021-04-26 20:07:00 +02:00
# # ####################################################
# # 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):
#
2021-04-26 20:07:00 +02:00
# f_trc_lst = open( os.path.join(context['temp_directory'],'tmp_trace_5477.lst'), 'w')
# subprocess.call([fb_home+'fbsvcmgr', 'localhost:service_mgr', 'action_trace_list'], stdout=f_trc_lst)
# f_trc_lst.close()
#
2021-04-26 20:07:00 +02:00
# # !!! DO NOT REMOVE THIS LINE !!!
# time.sleep(1)
#
2021-04-26 20:07:00 +02:00
# 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
# f.close()
# # Result: `trcssn` is ID of active trace session. Now we have to terminate it:
#
2021-04-26 20:07:00 +02:00
# con1 = fdb.connect(dsn=dsn)
# cur1=con1.cursor()
# cur1.execute('select 1 from rdb$database')
# for r in cur1:
# pass
# con1.close()
#
2021-04-26 20:07:00 +02:00
# # Let trace log to be entirely written on disk:
# time.sleep(2)
#
2021-04-26 20:07:00 +02:00
# # ####################################################
# # 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')
# subprocess.call([fb_home+'fbsvcmgr', 'localhost:service_mgr', 'action_trace_stop','trc_id', trcssn], stdout=fn_nul)
# fn_nul.close()
# # DO NOT REMOVE THIS LINE:
# time.sleep(2)
#
2021-04-26 20:07:00 +02:00
# p_trace.terminate()
# f_trc_log.close()
# f_trc_err.close()
#
2021-04-26 20:07:00 +02:00
# # Following file should be EMPTY:
# ################
#
2021-04-26 20:07:00 +02:00
# 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)
#
2021-04-26 20:07:00 +02:00
# letters_dict={}
# with open( f_trc_log.name,'rb') as f:
# letters_dict = Counter(f.read())
#
2021-04-26 20:07:00 +02:00
# nl_count = letters_dict['\\n']
# cr_count = letters_dict['\\r']
#
2021-04-26 20:07:00 +02:00
# print( 'EXPECTED.' if nl_count >= 1 and abs(nl_count - cr_count) <= 1 else 'FAIL: empty log or NL count differ than CR.' )
#
2021-04-26 20:07:00 +02:00
# # CLEANUP
# #########
# f_list=(f_trc_cfg, f_trc_lst, f_trc_log, f_trc_err)
# for i in range(len(f_list)):
# if os.path.isfile(f_list[i].name):
# os.remove(f_list[i].name)
#
#
2021-04-26 20:07:00 +02:00
#---