6
0
mirror of https://github.com/FirebirdSQL/firebird-qa.git synced 2025-01-23 22:13:05 +01:00
firebird-qa/tests/bugs/core_6395_test.py

197 lines
7.2 KiB
Python
Raw Normal View History

2021-04-26 20:07:00 +02:00
#coding:utf-8
2022-01-27 20:08:36 +01:00
"""
ID: issue-6633
ISSUE: 6633
TITLE: Allow usage of time zone displacement in config DefaultTimeZone
DESCRIPTION:
We make backup of current firebird.conf for changing it two times:
1. Add line with DefaultTimeZone = -7:00 and get local time by making *LOCAL* connect to current DB;
2. Restore previous firebird.conf from its .bak-copy do second change: add line with DefaultTimeZone = 7:00.
Then we run second local connect.
Each connect will ask FB to return CURRENT_TIME value (with casting it to '%H:%M:%S' format).
Expected result: values must change from 1st to 2nd run for 14 hours (840 minutes).
::: NB :::
1. Affect of changed parameter DefaultTimeZone can be seen only if DB is attached using *LOCAL* protocol.
Attempt to connect using remote protocol will fail: engine returns previous value of DefaultTimeZone.
One need to wait at least 130 seconds after changing firebird.conf for new value be returned at this case!
The reason of that is 10+60+60 seconds which are needed to fully unload shmem-related structures from memory.
Explanation from Vlad: letter 24.01.2021 18:00, subj: "System audit in FB. Is there some kind of timeout of 130 seconds ?"
(it was discussion about attempts make test for CORE-5993)
See also: http://tracker.firebirdsql.org/browse/CORE-6476
2. FDB driver loads client library only *once* before this test launch and, in turn, this library reads firebird.conf.
For this reason we have to launch separate (child) process two times, which will be forced to load firebird.conf
every launch. This is why subprocess.call(['isql', ...]) is needed here rather than just query DB using cursor of
pre-existing db_conn connection (see routine 'get_local_time').
Confirmed improvement on 4.0.0.2185.
Value of time did not differ on previous builds (checked 4..0.2170).
JIRA: CORE-6395
FBTEST: bugs.core_6395
2022-01-27 20:08:36 +01:00
"""
2021-04-26 20:07:00 +02:00
import pytest
2022-01-27 20:08:36 +01:00
from firebird.qa import *
2021-04-26 20:07:00 +02:00
2022-01-27 20:08:36 +01:00
db = db_factory()
2021-04-26 20:07:00 +02: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 = """
840
"""
2021-04-26 20:07:00 +02:00
2022-01-27 20:08:36 +01:00
@pytest.mark.skip('FIXME: firebird.conf')
@pytest.mark.version('>=4.0')
def test_1(act: Action):
pytest.fail("Not IMPLEMENTED")
2021-04-26 20:07:00 +02:00
# test_script_1
#---
2022-01-26 21:10:46 +01:00
#
2021-04-26 20:07:00 +02:00
# import sys
# import os
# import shutil
# import socket
# import getpass
# import time
# import datetime
# from datetime import timedelta
# import subprocess
# from fdb import services
2022-01-26 21:10:46 +01:00
#
2021-04-26 20:07:00 +02:00
# db_name=db_conn.database_name
# db_conn.close()
# #--------------------------------------------
2022-01-26 21:10:46 +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
2022-01-26 21:10:46 +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
2022-01-26 21:10:46 +01:00
#
2021-04-26 20:07:00 +02:00
# 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()
2022-01-26 21:10:46 +01:00
#
2021-04-26 20:07:00 +02:00
# #--------------------------------------------
2022-01-26 21:10:46 +01:00
#
2021-04-26 20:07:00 +02:00
# def cleanup( f_names_list ):
# global os
# for f in f_names_list:
# if type(f) == file:
# del_name = f.name
# elif type(f) == str:
# del_name = f
# else:
# print('Unrecognized type of element:', f, ' - can not be treated as file.')
# del_name = None
2022-01-26 21:10:46 +01:00
#
2021-04-26 20:07:00 +02:00
# if del_name and os.path.isfile( del_name ):
# os.remove( del_name )
2022-01-26 21:10:46 +01:00
#
2021-04-26 20:07:00 +02:00
# #--------------------------------------------
2022-01-26 21:10:46 +01:00
#
2021-04-26 20:07:00 +02:00
# def get_local_time( fb_home, db_name ):
2022-01-26 21:10:46 +01:00
#
2021-04-26 20:07:00 +02:00
# global flush_and_close
# global subprocess
# global cleanup
2022-01-26 21:10:46 +01:00
#
2021-04-26 20:07:00 +02:00
# sql_chk='select substring( cast(cast(current_time as time) as varchar(13)) from 1 for 8) from rdb$database'
2022-01-26 21:10:46 +01:00
#
2021-04-26 20:07:00 +02:00
# f_connect_sql = open( os.path.join(context['temp_directory'],'tmp_6396_check.sql'), 'w')
# f_connect_sql.write('set heading off; ' + sql_chk + ';' )
# flush_and_close( f_connect_sql )
2022-01-26 21:10:46 +01:00
#
2021-04-26 20:07:00 +02:00
# f_connect_log=open( os.path.join(context['temp_directory'],'tmp_6396_check.log'), 'w')
2022-01-26 21:10:46 +01:00
#
# ###############
# ### ACHTUNG ###
# ###############
# # LOCAL protocol must be used here!
# # Attempt to connect using remote protocol will fail: engine returns previous value of DefaultTimeZone.
# # One need to wait at least 130 seconds after changing firebird.conf for new value be returned at this case!
# # The reason of that is 10+60+60 seconds which are needed to fully unload shmem-related structures from memory.
# # Explanation from Vlad: letter 24.01.2021 18:00, subj: "System audit in FB. Is there some kind of timeout of 130 seconds ?"
# # (it was discussion about attempts make test for CORE-5993)
# # See also: http://tracker.firebirdsql.org/browse/CORE-6476
2022-01-26 21:10:46 +01:00
#
2021-04-26 20:07:00 +02:00
# subprocess.call( [ context['isql_path'], db_name, "-i", f_connect_sql.name ], stdout=f_connect_log, stderr=subprocess.STDOUT )
# flush_and_close( f_connect_log )
2022-01-26 21:10:46 +01:00
#
2021-04-26 20:07:00 +02:00
# changed_time = '00:00:00'
# with open(f_connect_log.name,'r') as f:
# for line in f:
# if line.split():
# changed_time = line.strip()
2022-01-26 21:10:46 +01:00
#
2021-04-26 20:07:00 +02:00
# cleanup( [x.name for x in (f_connect_sql, f_connect_log)] )
# return changed_time
2022-01-26 21:10:46 +01:00
#
2021-04-26 20:07:00 +02:00
# #---------------------------------------------
2022-01-26 21:10:46 +01:00
#
2021-04-26 20:07:00 +02:00
# svc = services.connect(host='localhost', user=user_name, password=user_password)
# fb_home = svc.get_home_directory()
# svc.close()
2022-01-26 21:10:46 +01:00
#
2021-04-26 20:07:00 +02:00
# dts = datetime.datetime.now().strftime("%y%m%d_%H%M%S")
2022-01-26 21:10:46 +01:00
#
2021-04-26 20:07:00 +02:00
# fbconf_cur = os.path.join(fb_home, 'firebird.conf')
# fbconf_bak = os.path.join(context['temp_directory'], 'firebird_'+dts+'.bak')
2022-01-26 21:10:46 +01:00
#
2021-04-26 20:07:00 +02:00
# shutil.copy2( fbconf_cur, fbconf_bak )
2022-01-26 21:10:46 +01:00
#
2021-04-26 20:07:00 +02:00
# f_fbconf=open( fbconf_cur, 'r')
# fbconf_content=f_fbconf.readlines()
# flush_and_close( f_fbconf )
2022-01-26 21:10:46 +01:00
#
2021-04-26 20:07:00 +02:00
# for i,s in enumerate( fbconf_content ):
# line = s.lower().lstrip()
# if line.startswith( 'DefaultTimeZone'.lower() ):
# fbconf_content[i] = '# [temply commented] ' + s
2022-01-26 21:10:46 +01:00
#
2021-04-26 20:07:00 +02:00
# text2app='''
# ### TEMPORARY CHANGED BY FBTEST FRAMEWORK ###
# DefaultTimeZone = -7:00
# ##############################################
# '''
2022-01-26 21:10:46 +01:00
#
2021-04-26 20:07:00 +02:00
# f_fbconf=open( fbconf_cur, 'w')
# f_fbconf.writelines( fbconf_content + [ '\\n' + x for x in text2app.split('\\n') ] )
# flush_and_close( f_fbconf )
# #..........................................
2022-01-26 21:10:46 +01:00
#
2021-04-26 20:07:00 +02:00
# changed_time1 = get_local_time( fb_home, db_name )
2022-01-26 21:10:46 +01:00
#
2021-04-26 20:07:00 +02:00
# # RESTORE previous content of firebird.conf. This must be done BEFORE drop mapping!
# shutil.copy2( fbconf_bak, fbconf_cur )
2022-01-26 21:10:46 +01:00
#
2021-04-26 20:07:00 +02:00
# ##################################################
2022-01-26 21:10:46 +01:00
#
2021-04-26 20:07:00 +02:00
# text2app='''
# ### TEMPORARY CHANGED BY FBTEST FRAMEWORK ###
# DefaultTimeZone = +7:00
# ##############################################
# '''
2022-01-26 21:10:46 +01:00
#
2021-04-26 20:07:00 +02:00
# f_fbconf=open( fbconf_cur, 'w')
# f_fbconf.writelines( fbconf_content + [ '\\n' + x for x in text2app.split('\\n') ] )
# flush_and_close( f_fbconf )
2022-01-26 21:10:46 +01:00
#
2021-04-26 20:07:00 +02:00
# changed_time2 = get_local_time( fb_home, db_name )
2022-01-26 21:10:46 +01:00
#
2021-04-26 20:07:00 +02:00
# # RESTORE previous content of firebird.conf. This must be done BEFORE drop mapping!
# shutil.move( fbconf_bak, fbconf_cur )
2022-01-26 21:10:46 +01:00
#
2021-04-26 20:07:00 +02:00
# print( (datetime.datetime.strptime(changed_time2, '%H:%M:%S') - datetime.datetime.strptime(changed_time1, '%H:%M:%S')).seconds // 60 )
2022-01-26 21:10:46 +01:00
#
#
2021-04-26 20:07:00 +02:00
#---