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_5118_test.py

194 lines
6.2 KiB
Python
Raw Normal View History

2021-04-26 20:07:00 +02:00
#coding:utf-8
#
# id: bugs.core_5118
# title: Indices on computed fields are broken after restore (all keys are NULL)
2021-11-29 20:54:28 +01:00
# decription:
2021-04-26 20:07:00 +02:00
# Confirmed wrong result on: 2.5.9.27117, 3.0.4.33054
# Works fine on:
# 4.0.0.1455: OK, 3.656s.
# 3.0.5.33109: OK, 2.641s.
# 2.5.9.27129: OK, 1.569s.
2021-11-29 20:54:28 +01:00
#
2021-04-26 20:07:00 +02:00
# tracker_id: CORE-5118
# min_versions: ['2.5.9']
# versions: 2.5.9
# qmid: None
import pytest
2021-11-29 20:54:28 +01:00
from io import BytesIO
from firebird.qa import db_factory, python_act, Action
from firebird.driver import SrvRestoreFlag
2021-04-26 20:07:00 +02:00
# version: 2.5.9
# resources: None
substitutions_1 = []
init_script_1 = """
recreate table test (
id int,
x varchar(10),
y varchar(10) ,
concat_text computed by (x || ' ' || y)
);
commit;
insert into test(id, x, y) values (1, 'nom1', 'prenom1');
insert into test(id, x, y) values (2, 'nom2', 'prenom2');
insert into test(id, x, y) values (3, 'nom3', 'prenom3');
commit;
create index test_concat_text on test computed by ( concat_text );
commit;
2021-11-29 20:54:28 +01:00
"""
2021-04-26 20:07:00 +02:00
db_1 = db_factory(sql_dialect=3, init=init_script_1)
# test_script_1
#---
2021-11-29 20:54:28 +01:00
#
2021-04-26 20:07:00 +02:00
# import os
# import time
# import subprocess
2021-11-29 20:54:28 +01:00
#
2021-04-26 20:07:00 +02:00
# os.environ["ISC_USER"] = user_name
# os.environ["ISC_PASSWORD"] = user_password
2021-11-29 20:54:28 +01:00
#
2021-04-26 20:07:00 +02:00
# tmpsrc = db_conn.database_name
# tmpbkp = os.path.splitext(tmpsrc)[0] + '.fbk'
# tmpres = os.path.splitext(tmpsrc)[0] + '.tmp'
2021-11-29 20:54:28 +01:00
#
2021-04-26 20:07:00 +02:00
# db_conn.close()
2021-11-29 20:54:28 +01:00
#
2021-04-26 20:07:00 +02:00
# #--------------------------------------------
2021-11-29 20:54:28 +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-29 20:54:28 +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-29 20:54:28 +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-11-29 20:54:28 +01:00
#
2021-04-26 20:07:00 +02:00
# #--------------------------------------------
2021-11-29 20:54:28 +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-11-29 20:54:28 +01:00
#
2021-04-26 20:07:00 +02:00
# if del_name and os.path.isfile( del_name ):
# os.remove( del_name )
2021-11-29 20:54:28 +01:00
#
2021-04-26 20:07:00 +02:00
# #--------------------------------------------
2021-11-29 20:54:28 +01:00
#
#
2021-04-26 20:07:00 +02:00
# # NB: we have ALWAYS to drop file that is to be target for restoring process,
# # otherwise one can get:
# # Statement failed, SQLSTATE = HY000
# # unsupported on-disk structure for file ...; found 12.0, support 13.0
# # (it will occur if THIS test was already run for older FB major version)
2021-11-29 20:54:28 +01:00
#
2021-04-26 20:07:00 +02:00
# cleanup( (tmpres,) )
2021-11-29 20:54:28 +01:00
#
2021-04-26 20:07:00 +02:00
# f_backup_log=open(os.devnull, 'w')
# f_backup_err=open( os.path.join(context['temp_directory'],'tmp_backup_5118.err'), 'w')
2021-11-29 20:54:28 +01:00
#
2021-04-26 20:07:00 +02:00
# subprocess.call([context['fbsvcmgr_path'],"localhost:service_mgr",
# "action_backup",
# "dbname", tmpsrc,
# "bkp_file", tmpbkp,
# "verbose"
# ],
2021-11-29 20:54:28 +01:00
# stdout=f_backup_log,
2021-04-26 20:07:00 +02:00
# stderr=f_backup_err
# )
# flush_and_close( f_backup_log )
# flush_and_close( f_backup_err )
2021-11-29 20:54:28 +01:00
#
2021-04-26 20:07:00 +02:00
# f_restore_log = open( os.path.join(context['temp_directory'],'tmp_restore_5118.log'), 'w')
# f_restore_err = open( os.path.join(context['temp_directory'],'tmp_restore_5118.err'), 'w')
2021-11-29 20:54:28 +01:00
#
2021-04-26 20:07:00 +02:00
# subprocess.call([context['fbsvcmgr_path'],"localhost:service_mgr",
# "action_restore",
# "bkp_file", tmpbkp,
# "dbname", tmpres,
# "res_replace",
# "verbose"
# ],
2021-11-29 20:54:28 +01:00
# stdout=f_restore_log,
2021-04-26 20:07:00 +02:00
# stderr=f_restore_err
# )
2021-11-29 20:54:28 +01:00
#
2021-04-26 20:07:00 +02:00
# flush_and_close( f_restore_log )
# flush_and_close( f_restore_err )
2021-11-29 20:54:28 +01:00
#
2021-04-26 20:07:00 +02:00
# with open(f_backup_err.name, 'r') as f:
# for line in f:
# print( "BACKUP STDERR: "+line )
2021-11-29 20:54:28 +01:00
#
#
2021-04-26 20:07:00 +02:00
# # Result of this filtering should be EMPTY:
# with open( f_restore_err.name,'r') as f:
# for line in f:
# print( "RESTORE STDERR: "+line )
2021-11-29 20:54:28 +01:00
#
#
2021-04-26 20:07:00 +02:00
# runProgram( 'isql', [ 'localhost:' + tmpres, '-q' ], 'set list on; set plan on; set count on; select * from test order by concat_text;' )
2021-11-29 20:54:28 +01:00
#
2021-04-26 20:07:00 +02:00
# #####################################################################
# # Cleanup:
2021-11-29 20:54:28 +01:00
# # do NOT remove this pause otherwise some of logs will not be enable for deletion and test will finish with
2021-04-26 20:07:00 +02:00
# # Exception raised while executing Python test script. exception: WindowsError: 32
# time.sleep(1)
# cleanup( (f_backup_log, f_backup_err, f_restore_log, f_restore_err, tmpbkp, tmpres) )
2021-11-29 20:54:28 +01:00
#
2021-04-26 20:07:00 +02:00
#---
2021-11-29 20:54:28 +01:00
act_1 = python_act('db_1', substitutions=substitutions_1)
2021-04-26 20:07:00 +02:00
expected_stdout_1 = """
PLAN (TEST ORDER TEST_CONCAT_TEXT)
ID 1
X nom1
Y prenom1
CONCAT_TEXT nom1 prenom1
ID 2
X nom2
Y prenom2
CONCAT_TEXT nom2 prenom2
ID 3
X nom3
Y prenom3
CONCAT_TEXT nom3 prenom3
Records affected: 3
2021-11-29 20:54:28 +01:00
"""
@pytest.mark.version('>=3.0')
def test_1(act_1: Action):
with act_1.connect_server() as srv:
backup = BytesIO()
srv.database.local_backup(database=act_1.db.db_path, backup_stream=backup)
2021-11-29 20:54:28 +01:00
backup.seek(0)
srv.database.local_restore(database=act_1.db.db_path, backup_stream=backup,
2021-11-29 20:54:28 +01:00
flags=SrvRestoreFlag.REPLACE)
act_1.expected_stdout = expected_stdout_1
act_1.isql(switches=['-q'],
input='set list on; set plan on; set count on; select * from test order by concat_text;')
assert act_1.clean_stdout == act_1.clean_expected_stdout