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

156 lines
5.3 KiB
Python

#coding:utf-8
"""
ID: issue-6932
ISSUE: 6932
TITLE: GTT's pages are not released while dropping it
DESCRIPTION:
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 <GTT_DIR> 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 <ITER_COUNT> 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.
BEFORE 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.
"""
import pytest
from firebird.qa import *
db = db_factory()
act = python_act('db')
expected_stdout = """
GTT file size remains the same.
"""
@pytest.mark.skip('FIXME: Not IMPLEMENTED')
@pytest.mark.version('>=4.0')
@pytest.mark.platform('Windows')
def test_1(act: Action):
pytest.fail("Not IMPLEMENTED")
# 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) )
#
#---