diff --git a/tests/bugs/core_6932_test.py b/tests/bugs/core_6932_test.py new file mode 100644 index 00000000..5fabd528 --- /dev/null +++ b/tests/bugs/core_6932_test.py @@ -0,0 +1,165 @@ +#coding:utf-8 +# +# id: bugs.core_6932 +# title: GTT's pages are not released while dropping it +# decription: +# We extract value of config parameter 'TempTableDirectory' in order to get directory where GTT data are stored. +# If this parameter is undefined then we query environment variables: FIREBIRD_TMP; TEMP and TMP - and stop after +# finding first non-empty value in this list. Name of this folder is stored in GTT_DIR variable. +# +# Then we create GTT and add some data in it; file 'fb_table_*' will appear in after this. +# We have to obtain size of this file and invoke os.path.getsize(). Result will be NON-zero, despite that Windows +# 'dir' command shows that this file has size 0. We initialize list 'gtt_size_list' and save this size in it as +# 'initial' element (with index 0). +# +# After this, we make loop for iterations and do on each of them: +# * drop GTT; +# * create GTT (with new name); +# * add some data into just created GTT +# * get GTT file size and add it to the list for further analysis (see 'gtt_size_list.append(...)') +# +# Finally, we scan list 'gtt_size_list' (starting from 2nd element) and evaluate DIFFERENCE between size of GTT file +# that was obtained on Nth and (N-1)th iterations. MEDIAN value of this difference must be ZERO. +# +# NB-1. +# BEFOE this ticket was fixed, size of GTT grew noticeably only for the first ~10 iterations. +# This is example how size was changed (in percents): +# 26.88 +# 34.92 +# 12.69 +# 19.84 +# 11.91 +# 10.64 +# 14.43 +# 8.40 +# 7.75 +# For big numbers of ITER_COUNT values quickly tend to zero. +# AFTER this fix size is changed only for 2nd iteration (and not in every measure), for ~6%. +# All rest changes (startingfrom 3rd measure) must be zero. +# +# NB-2. Test implemented for Windows only: there is no ability to get name of GTT file on Linux +# because all such files marked as deleted immediately after creation. +# +# Confirmed bug on 5.0.0.169. +# Checked on: WI-V4.0.1.2578; WI-T5.0.0.181 -- all OK. +# +# +# tracker_id: CORE-6932 +# 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 = [] + +init_script_1 = """""" + +db_1 = db_factory(sql_dialect=3, init=init_script_1) + +# test_script_1 +#--- +# import os +# import sys +# import glob +# # import fdb +# +# ITER_COUNT = 10 +# FB_GTT_PATTERN = 'fb_table_*' +# +# #FB_CLNT = r'C:\\FB(cs +# bclient.dll' +# #DB_NAME = 'localhost:e50' +# +# GTT_CREATE_TABLE="recreate global temporary table gtt_%(gtt_name_idx)s(s varchar(1000) unique) on commit preserve rows" +# GTT_ADD_RECORDS="insert into gtt_%(gtt_name_idx)s select lpad('', 1000, uuid_to_char(gen_uuid())) from rdb$types,rdb$types rows 1000" +# GTT_DROP_TABLE="drop table gtt_%(gtt_prev_idx)s" +# +# #con = fdb.connect( dsn = DB_NAME, fb_library_name = FB_CLNT) +# +# cur = db_conn.cursor() +# +# GTT_DIR = '' +# cur.execute("select coalesce(rdb$config_value,'') from rdb$config where rdb$config_name = 'TempTableDirectory'") +# for r in cur: +# GTT_DIR = r[0] +# cur.close() +# +# if not GTT_DIR: +# GTT_DIR = os.environ.get("FIREBIRD_TMP", '') +# +# if not GTT_DIR: +# GTT_DIR = os.environ.get("TEMP", '') +# +# if not GTT_DIR: +# GTT_DIR = os.environ.get("TMP", '') +# +# if not GTT_DIR: +# print('### ABEND ### Could not get directory where GTT data are stored.') +# exit(1) +# +# gtt_dir_init = glob.glob( os.path.join(GTT_DIR, FB_GTT_PATTERN) ) +# +# gtt_name_idx = 0 +# db_conn.execute_immediate(GTT_CREATE_TABLE % locals()) +# db_conn.commit() +# db_conn.execute_immediate(GTT_ADD_RECORDS % locals()) +# db_conn.commit() +# +# gtt_dir_curr = glob.glob( os.path.join(GTT_DIR, FB_GTT_PATTERN) ) +# +# gtt_new_file = list(set(gtt_dir_curr) - set(gtt_dir_init))[0] +# +# #print('name of GTT: ',gtt_new_file, ', size: ', os.path.getsize(gtt_new_file)) +# +# gtt_size_list = [ (0,os.path.getsize(gtt_new_file)) ] +# for gtt_name_idx in range(1,ITER_COUNT): +# # print('Iter No %d' % gtt_name_idx) +# gtt_prev_idx = gtt_name_idx-1 +# db_conn.execute_immediate(GTT_DROP_TABLE % locals()) +# db_conn.commit() +# db_conn.execute_immediate(GTT_CREATE_TABLE % locals()) +# db_conn.commit() +# db_conn.execute_immediate(GTT_ADD_RECORDS % locals()) +# db_conn.commit() +# #print('size: %d' % os.path.getsize(gtt_new_file) ) +# #print('---------------------') +# gtt_size_list.append( (gtt_name_idx,os.path.getsize(gtt_new_file)) ) +# +# size_changes_percent_list = [] +# for k in range(1,len(gtt_size_list)): +# #print(k,':', gtt_size_list[k][1], gtt_size_list[k-1][1], 100.00 * gtt_size_list[k][1] / gtt_size_list[k-1][1] - 100 ) +# size_changes_percent_list.append( 100.00 * gtt_size_list[k][1] / gtt_size_list[k-1][1] - 100 ) +# +# #for p in sorted(size_changes_percent_list): +# # print(p) +# #print('--------------------------------------') +# +# n = len(size_changes_percent_list) +# +# median_size_change_percent = sorted(size_changes_percent_list)[ min(n-1, int(n/2)) ] +# if median_size_change_percent == 0: +# print( 'GTT file size remains the same.' ) +# else: +# print('GTT file size UNEXPECTEDLY INCREASED. Check percentage:') +# for p in size_changes_percent_list: +# # print( round(p,2) ) +# print( '{:.2f}'.format(p) ) +# +#--- +act_1 = python_act('db_1', substitutions=substitutions_1) + +expected_stdout_1 = """ + GTT file size remains the same. +""" + +@pytest.mark.version('>=4.0') +@pytest.mark.platform('Windows') +def test_1(act_1: Action): + pytest.fail("Test not IMPLEMENTED") + + diff --git a/tests/bugs/core_6947_test.py b/tests/bugs/core_6947_test.py new file mode 100644 index 00000000..cb0dcc4e --- /dev/null +++ b/tests/bugs/core_6947_test.py @@ -0,0 +1,188 @@ +#coding:utf-8 +# +# id: bugs.core_6947 +# title: Query to mon$ tables does not return data when the encryption/decryption thread is running +# decription: +# Test creates table with wide indexed column and add some data to it. +# Volume of data must be big enough enough so that the encryption process does not have time to end in 1 second. +# +# Then ALTER DATABASE ENCRYPT ... is called and we allow encryption process to work for 1 second. +# After this we query MON$DATABASE and check that MON$CRYPT_STATE column has value = 3 ('is encrypting'). +# Before fix this value always was 1, i.e. 'fully encrypted' - because control returned to 'main' code only +# after encryption process was completed. +# +# Note: name for encryption plugin differs on Windows vs Linux: +# PLUGIN_NAME = 'dbcrypt' if os.name == 'nt' else '"fbSampleDbCrypt"' +# +# Confirmed bug on 5.0.0.219 (Windows), 5.0.0.236 (Linux). +# Checked on 5.0.0.240 (Windows; SS/Cs), 5.0.0.241 (Linux; SS/CS). +# +# tracker_id: CORE-6947 +# min_versions: ['5.0.0'] +# versions: 5.0 +# qmid: None + +import pytest +from firebird.qa import db_factory, python_act, Action + +# version: 5.0 +# resources: None + +substitutions_1 = [] + +init_script_1 = """""" + +db_1 = db_factory(sql_dialect=3, init=init_script_1) + +# test_script_1 +#--- +# +# import os +# import time +# import subprocess +# import re +# import fdb +# +# os.environ["ISC_USER"] = user_name +# os.environ["ISC_PASSWORD"] = user_password +# engine = db_conn.engine_version +# 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.') +# print('type(f_names_list[i])=',type(f_names_list[i])) +# del_name = None +# +# if del_name and os.path.isfile( del_name ): +# os.remove( del_name ) +# +# #-------------------------------------------- +# +# tmpfdb='$(DATABASE_LOCATION)'+'tmp_core_6947.fdb' +# +# cleanup( (tmpfdb,) ) +# +# con = fdb.create_database( dsn = tmpfdb, page_size = 4096 ) +# con.close() +# runProgram('gfix',[tmpfdb,'-w','async']) +# +# con = fdb.connect( dsn = tmpfdb ) +# con.execute_immediate( 'create table test(s varchar(1000))' ) +# con.commit() +# +# sql_init=''' +# execute block as +# declare n int = 100000; +# begin +# while (n>0) do +# begin +# insert into test(s) values( lpad('', 1000, uuid_to_char(gen_uuid())) ); +# n = n-1; +# end +# end +# ''' +# con.execute_immediate(sql_init) +# con.commit() +# con.execute_immediate( 'create index test_s on test(s)' ) +# con.commit() +# +# con.close() +# runProgram('gfix',[tmpfdb,'-w','sync']) +# +# #----------------------------------------------------- +# +# # Name of encryption plugin depends on OS: +# # * for Windows we (currently) use plugin by IBSurgeon, its name is 'dbcrypt'; +# # * for Linux we use: +# # ** 'DbCrypt_example' for FB 3.x +# # ** 'fbSampleDbCrypt' for FB 4.x+ +# # +# PLUGIN_NAME = 'dbcrypt' if os.name == 'nt' else ( '"fbSampleDbCrypt"' if engine >= 4.0 else '"DbCrypt_example"') +# +# customTPB = ( [ fdb.isc_tpb_read_committed, fdb.isc_tpb_rec_version, fdb.isc_tpb_nowait ] ) +# con = fdb.connect( dsn = tmpfdb, isolation_level = customTPB ) +# cur = con.cursor() +# +# ############################################## +# # WARNING! Do NOT use 'connection_obj.execute_immediate()' for ALTER DATABASE ENCRYPT... command! +# # There is bug in FB driver which leads this command to fail with 'token unknown' message +# # The reason is that execute_immediate() silently set client dialect = 0 and any encryption statement +# # can not be used for such value of client dialect. +# # One need to to use only cursor_obj.execute() for encryption! +# # See letter from Pavel Cisar, 20.01.20 10:36 +# ############################################## +# cur.execute('alter database encrypt with %(PLUGIN_NAME)s key Red' % locals()) +# con.commit() +# +# # Let encryption process start its job: +# time.sleep(1) +# +# # Before this ticket was fixed query to mon$ tables did not return data until encryption fully completed. +# # This means that we could see only mon$crypt_state = 1 ("fully encrypted"). +# # After fix, we must see that DB is currently encrypting: +# # +# crypt_state_map = {0: 'not encrypted', 1: 'fully encrypted', 2: 'is decrypting', 3: 'is encrypting'} +# cur.execute('select m.mon$crypt_state from mon$database m') +# for r in cur: +# db_crypt_state = crypt_state_map.get( r[0], 'UNKNOWN' ) +# +# cur.close() +# con.close() +# +# print('DB encryption state: %s.' % db_crypt_state) +# +# #---------------------------- shutdown temp DB -------------------- +# +# f_dbshut_log = open( os.path.join(context['temp_directory'],'tmp_dbshut_6947.log'), 'w') +# subprocess.call( [ context['gfix_path'], 'localhost:'+tmpfdb, "-shut", "full", "-force", "0" ], +# stdout = f_dbshut_log, +# stderr = subprocess.STDOUT +# ) +# flush_and_close( f_dbshut_log ) +# +# with open( f_dbshut_log.name,'r') as f: +# for line in f: +# print("Unexpected error on SHUTDOWN temp database: "+line) +# +# +# # CLEANUP +# ######### +# time.sleep(1) +# cleanup( ( f_dbshut_log,tmpfdb ) ) +# +#--- +act_1 = python_act('db_1', substitutions=substitutions_1) + +expected_stdout_1 = """ + DB encryption state: is encrypting. +""" + +@pytest.mark.version('>=5.0') +def test_1(act_1: Action): + pytest.fail("Test not IMPLEMENTED") + + diff --git a/tests/bugs/core_6987_test.py b/tests/bugs/core_6987_test.py new file mode 100644 index 00000000..b711d502 --- /dev/null +++ b/tests/bugs/core_6987_test.py @@ -0,0 +1,64 @@ +#coding:utf-8 +# +# id: bugs.core_6987 +# title: DATEDIFF does not support fractional value for MILLISECOND +# decription: +# Checked on 5.0.0.240; 4.0.1.2621; 3.0.8.33506. +# +# tracker_id: CORE-6987 +# min_versions: [] +# versions: 3.0.8 +# qmid: None + +import pytest +from firebird.qa import db_factory, isql_act, Action + +# version: 3.0.8 +# resources: None + +substitutions_1 = [('^((?!sqltype:|DD_).)*$', ''), ('[ \t]+', ' '), ('.*alias:.*', '')] + +init_script_1 = """""" + +db_1 = db_factory(sql_dialect=3, init=init_script_1) + +test_script_1 = """ + set sqlda_display on; + set list on; + + select datediff(millisecond from timestamp '0001-01-01' to timestamp '0001-01-01 00:00:00.0001') dd_01 from rdb$database; + select datediff(millisecond from timestamp '9999-12-31 23:59:59.9999' to timestamp '0001-01-01 00:00:00.0001') dd_02 from rdb$database; + + select datediff(millisecond from time '00:00:00' to time '00:00:00.0001') dd_03 from rdb$database; + select datediff(millisecond from time '23:59:59' to time '00:00:00.0001') dd_04 from rdb$database; + +""" + +act_1 = isql_act('db_1', test_script_1, substitutions=substitutions_1) + +expected_stdout_1 = """ + 01: sqltype: 580 INT64 scale: -1 subtype: 0 len: 8 + : name: DATEDIFF alias: DD_01 + : table: owner: + DD_01 0.1 + + 01: sqltype: 580 INT64 scale: -1 subtype: 0 len: 8 + : name: DATEDIFF alias: DD_02 + + DD_02 -315537897599999.8 + + 01: sqltype: 580 INT64 scale: -1 subtype: 0 len: 8 + : name: DATEDIFF alias: DD_03 + DD_03 0.1 + + 01: sqltype: 580 INT64 scale: -1 subtype: 0 len: 8 + : name: DATEDIFF alias: DD_04 + DD_04 -86398999.9 +""" + +@pytest.mark.version('>=3.0.8') +def test_1(act_1: Action): + act_1.expected_stdout = expected_stdout_1 + act_1.execute() + assert act_1.clean_stdout == act_1.clean_expected_stdout +