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

138 lines
4.8 KiB
Python
Raw Normal View History

2021-04-26 20:07:00 +02:00
#coding:utf-8
#
# id: bugs.core_5364
# title: gfix -online normal <db> (being issued in window #1) does not produce error when there is sysdba attachment in window #2
2021-12-06 19:23:35 +01:00
# decription:
2021-04-26 20:07:00 +02:00
# We create new DB and immediately change its state to single-user maintanance.
# Then we attach to this DB ans run (in separate process) 'gfix -online normal <localhost:this_db>'.
# This command must produce in its STDERR error: "database ... shutdown" - and we check that this actually occurs.
# Also, we check that after reconnect to this DB value of mon$database.mon$shutdown_mode remains the same: 2.
2021-12-06 19:23:35 +01:00
#
2021-04-26 20:07:00 +02:00
# Confirmed bug on: 4.0.0.1850 SS, 3.0.6.33276 SS - no error when doing 'gfix -online normal'.
# Checked on 4.0.0.1881 SS, 3.0.6.33283 SS -- all fine, DB state is not changed to normal.
2021-12-06 19:23:35 +01:00
#
2021-04-26 20:07:00 +02:00
# tracker_id: CORE-5364
# min_versions: ['3.0.6']
# versions: 3.0.6
# qmid: None
import pytest
2021-12-06 19:23:35 +01:00
from firebird.qa import db_factory, python_act, Action
from firebird.driver import ShutdownMode, ShutdownMethod
2021-04-26 20:07:00 +02:00
# version: 3.0.6
# resources: None
substitutions_1 = [('database .* shutdown', 'database shutdown')]
init_script_1 = """"""
db_1 = db_factory(sql_dialect=3, init=init_script_1)
# test_script_1
#---
2021-12-06 19:23:35 +01:00
#
2021-04-26 20:07:00 +02:00
# import os
# import time
# import subprocess
# from subprocess import Popen
# from fdb import services
2021-12-06 19:23:35 +01:00
#
2021-04-26 20:07:00 +02:00
# os.environ["ISC_USER"] = user_name
# os.environ["ISC_PASSWORD"] = user_password
# db_conn.close()
# #--------------------------------------------
2021-12-06 19:23:35 +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-12-06 19:23:35 +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-12-06 19:23:35 +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()
2021-12-06 19:23:35 +01:00
#
2021-04-26 20:07:00 +02:00
# #--------------------------------------------
2021-12-06 19:23:35 +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 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
2021-12-06 19:23:35 +01:00
#
2021-04-26 20:07:00 +02:00
# if del_name and os.path.isfile( del_name ):
# os.remove( del_name )
2021-12-06 19:23:35 +01:00
#
2021-04-26 20:07:00 +02:00
# #--------------------------------------------
2021-12-06 19:23:35 +01:00
#
2021-04-26 20:07:00 +02:00
# tmpfdb = os.path.join( context['temp_directory'], 'tmp_5364.fdb')
# cleanup( (tmpfdb,) )
2021-12-06 19:23:35 +01:00
#
2021-04-26 20:07:00 +02:00
# con1=fdb.create_database(dsn = 'localhost:' + tmpfdb)
# con1.close()
# subprocess.call( [ context['gfix_path'], 'localhost:' + tmpfdb, '-shut', 'single', '-force', '0'] )
2021-12-06 19:23:35 +01:00
#
2021-04-26 20:07:00 +02:00
# con1=fdb.connect(dsn = 'localhost:' + tmpfdb)
2021-12-06 19:23:35 +01:00
#
2021-04-26 20:07:00 +02:00
# f_gfix_online_log=open( os.path.join(context['temp_directory'],'tmp_5364_online.log'), 'w', buffering = 0)
# f_gfix_online_err=open( os.path.join(context['temp_directory'],'tmp_5364_online.err'), 'w', buffering = 0)
2021-12-06 19:23:35 +01:00
#
2021-04-26 20:07:00 +02:00
# subprocess.call( [ context['gfix_path'], 'localhost:' + tmpfdb, '-online', 'normal'], stdout=f_gfix_online_log, stderr=f_gfix_online_err )
2021-12-06 19:23:35 +01:00
#
2021-04-26 20:07:00 +02:00
# flush_and_close( f_gfix_online_log )
# flush_and_close( f_gfix_online_err )
2021-12-06 19:23:35 +01:00
#
2021-04-26 20:07:00 +02:00
# con1.close()
2021-12-06 19:23:35 +01:00
#
2021-04-26 20:07:00 +02:00
# con1=fdb.connect(dsn = 'localhost:' + tmpfdb)
# cur1=con1.cursor()
# cur1.execute('select d.mon$shutdown_mode from mon$database d')
# for r in cur1:
# print( 'DB shutdown mode:', r[0] )
# cur1.close()
# con1.close()
2021-12-06 19:23:35 +01:00
#
2021-04-26 20:07:00 +02:00
# with open(f_gfix_online_err.name, 'r') as f:
# for line in f:
# if line.split():
# print(line)
2021-12-06 19:23:35 +01:00
#
2021-04-26 20:07:00 +02:00
# # cleanup
# ##########
# time.sleep(1)
# cleanup( (f_gfix_online_log, f_gfix_online_err, tmpfdb) )
2021-12-06 19:23:35 +01:00
#
2021-04-26 20:07:00 +02:00
# # database C:\\FBTESTING\\QA\\FBT-REPO\\TMP\\TMP_5364.FDB shutdown
# # database /opt/scripts/qa-rundaily/fbt-repo/tmp/tmp_5364.fdb shutdown
2021-12-06 19:23:35 +01:00
#
#
2021-04-26 20:07:00 +02:00
#---
2021-12-06 19:23:35 +01:00
act_1 = python_act('db_1', substitutions=substitutions_1)
2021-04-26 20:07:00 +02:00
2021-12-06 19:23:35 +01:00
expected_stderr_1 = """
database /test/test.fdb shutdown
"""
2021-04-26 20:07:00 +02:00
2021-12-06 19:23:35 +01:00
@pytest.mark.version('>=3.0.6')
def test_1(act_1: Action):
with act_1.connect_server() as srv:
srv.database.shutdown(database=act_1.db.db_path, mode=ShutdownMode.SINGLE,
2021-12-06 19:23:35 +01:00
method=ShutdownMethod.FORCED, timeout=0)
with act_1.db.connect() as con:
c = con.cursor()
sh_mode = c.execute('select mon$shutdown_mode from mon$database').fetchone()[0]
act_1.expected_stderr = expected_stderr_1
act_1.gfix(switches=['-online', 'normal', act_1.db.dsn])
assert sh_mode == 2
assert act_1.clean_stderr == act_1.clean_expected_stderr