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

269 lines
8.5 KiB
Python
Raw Normal View History

2021-04-26 20:07:00 +02:00
#coding:utf-8
#
# id: bugs.core_2879
# title: Sweep could raise error : page 0 is of wrong type (expected 6, found 1)
2021-11-16 19:44:53 +01:00
# decription:
2021-04-26 20:07:00 +02:00
# Test receives content of firebird.log _before_ and _after_ running query that is show in the ticket.
# Then we compare these two files.
# Difference between them should relate ONLY to sweep start and finish details, and NOT about page wrong type.
2021-11-16 19:44:53 +01:00
#
2021-04-26 20:07:00 +02:00
# Checked on: WI-V2.5.7.27024, WI-V3.0.1.32570, WI-T4.0.0.316 -- all works OK.
# Refactored 01.02.2020, checked on:
# 4.0.0.1759 SS: 4.754s.
# 3.0.6.33240 SS: 3.704s.
# 2.5.9.27119 SS: 6.607s.
2021-11-16 19:44:53 +01:00
#
2021-04-26 20:07:00 +02:00
# tracker_id: CORE-2879
# min_versions: ['2.5.1']
# versions: 2.5.1
# qmid: None
import pytest
2021-11-16 19:44:53 +01:00
import time
import subprocess
from pathlib import Path
from difflib import unified_diff
from firebird.qa import db_factory, python_act, Action, temp_file
2021-04-26 20:07:00 +02:00
# version: 2.5.1
# resources: None
2021-11-16 19:44:53 +01:00
substitutions_1 = [('^((?!start|finish|expected|page|wrong).)*$', '')] # ('\t+', ' '),
2021-04-26 20:07:00 +02:00
init_script_1 = """"""
db_1 = db_factory(sql_dialect=3, init=init_script_1)
# test_script_1
#---
2021-11-16 19:44:53 +01:00
#
2021-04-26 20:07:00 +02:00
# import os
# import sys
# import subprocess
# from subprocess import Popen
# import difflib
# import time
# import datetime
# from datetime import datetime
2021-11-16 19:44:53 +01:00
#
2021-04-26 20:07:00 +02:00
# os.environ["ISC_USER"] = user_name
# os.environ["ISC_PASSWORD"] = user_password
2021-11-16 19:44:53 +01:00
#
2021-04-26 20:07:00 +02:00
# engine = str(db_conn.engine_version)
# db_file = db_conn.database_name # "$(DATABASE_LOCATION)bugs.core_2879.fdb"
2021-11-16 19:44:53 +01:00
#
2021-04-26 20:07:00 +02:00
# db_conn.close()
2021-11-16 19:44:53 +01:00
#
2021-04-26 20:07:00 +02:00
# #--------------------------------------------
2021-11-16 19:44:53 +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-16 19:44:53 +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-16 19:44:53 +01:00
#
2021-04-26 20:07:00 +02:00
# file_handle.flush()
# if file_handle.mode not in ('r', 'rb'):
# # otherwise: "OSError: [Errno 9] Bad file descriptor"!
# os.fsync(file_handle.fileno())
# file_handle.close()
2021-11-16 19:44:53 +01:00
#
2021-04-26 20:07:00 +02:00
# #--------------------------------------------
2021-11-16 19:44:53 +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 os.path.isfile( f_names_list[i]):
# os.remove( f_names_list[i] )
2021-11-16 19:44:53 +01:00
#
2021-04-26 20:07:00 +02:00
# #--------------------------------------------
2021-11-16 19:44:53 +01:00
#
2021-04-26 20:07:00 +02:00
# def svc_get_fb_log( engine, f_fb_log ):
2021-11-16 19:44:53 +01:00
#
2021-04-26 20:07:00 +02:00
# global subprocess
2021-11-16 19:44:53 +01:00
#
2021-04-26 20:07:00 +02:00
# if engine.startswith('2.5'):
# get_firebird_log_key='action_get_ib_log'
# else:
# get_firebird_log_key='action_get_fb_log'
2021-11-16 19:44:53 +01:00
#
2021-04-26 20:07:00 +02:00
# subprocess.call([ context['fbsvcmgr_path'],
# "localhost:service_mgr",
# get_firebird_log_key
# ],
2021-11-16 19:44:53 +01:00
# stdout=f_fb_log,
2021-04-26 20:07:00 +02:00
# stderr=subprocess.STDOUT
# )
2021-11-16 19:44:53 +01:00
#
2021-04-26 20:07:00 +02:00
# return
2021-11-16 19:44:53 +01:00
#
2021-04-26 20:07:00 +02:00
# #-----------------------------------------------------
2021-11-16 19:44:53 +01:00
#
2021-04-26 20:07:00 +02:00
# sql_ddl=''' set list on;
# set term ^;
# execute block returns (dts timestamp, sql varchar(80)) as
# declare i int;
# declare s varchar(256);
# begin
# i = 1;
# while (i < 32767) do
# begin
# s = 'tmp' || :i;
# dts = 'now';
# sql = 'create global temporary table ' || :s || ' (id int);';
# execute statement sql with autonomous transaction;
# suspend;
2021-11-16 19:44:53 +01:00
#
2021-04-26 20:07:00 +02:00
# dts = 'now';
# sql = 'drop table ' || :s || ';';
# execute statement sql with autonomous transaction;
# suspend;
2021-11-16 19:44:53 +01:00
#
2021-04-26 20:07:00 +02:00
# i = i + 1;
# end
# end ^
# set term ;^
# '''
2021-11-16 19:44:53 +01:00
#
2021-04-26 20:07:00 +02:00
# f_isql_cmd=open( os.path.join(context['temp_directory'],'tmp_make_lot_GTT_2879.sql'), 'w', buffering = 0)
# f_isql_cmd.write(sql_ddl)
# f_isql_cmd.close()
2021-11-16 19:44:53 +01:00
#
2021-04-26 20:07:00 +02:00
# # Get content of firebird.log BEFORE test:
# ##########################################
2021-11-16 19:44:53 +01:00
#
2021-04-26 20:07:00 +02:00
# f_fblog_before=open( os.path.join(context['temp_directory'],'tmp_2879_fblog_before.txt'), 'w', buffering = 0)
# svc_get_fb_log( engine, f_fblog_before )
# flush_and_close( f_fblog_before )
2021-11-16 19:44:53 +01:00
#
2021-04-26 20:07:00 +02:00
# # LAUNCH ISQL ASYNCHRONOUSLY
# ############################
2021-11-16 19:44:53 +01:00
#
2021-04-26 20:07:00 +02:00
# f_isql_log=open( os.path.join(context['temp_directory'],'tmp_make_lot_GTT_2879.log'), 'w', buffering = 0)
# p_isql=subprocess.Popen( [context['isql_path'], dsn, "-i", f_isql_cmd.name],
2021-11-16 19:44:53 +01:00
# stdout=f_isql_log,
2021-04-26 20:07:00 +02:00
# stderr=subprocess.STDOUT
# )
# #------------
# time.sleep(2)
# #------------
2021-11-16 19:44:53 +01:00
#
2021-04-26 20:07:00 +02:00
# # LAUNCH SWEEP while ISQL is working:
# # ############
# fbsvc_log=open( os.path.join(context['temp_directory'],'tmp_svc_2879.log'), 'w', buffering = 0)
# subprocess.call( [ context['fbsvcmgr_path'],"localhost:service_mgr", "action_repair", "dbname", db_file, "rpr_sweep_db"], stdout=fbsvc_log, stderr=subprocess.STDOUT )
# flush_and_close( fbsvc_log )
2021-11-16 19:44:53 +01:00
#
2021-04-26 20:07:00 +02:00
# p_isql.terminate()
# f_isql_log.close()
2021-11-16 19:44:53 +01:00
#
#
2021-04-26 20:07:00 +02:00
# # Get content of firebird.log AFTER test:
# #########################################
2021-11-16 19:44:53 +01:00
#
2021-04-26 20:07:00 +02:00
# f_fblog_after=open( os.path.join(context['temp_directory'],'tmp_2879_fblog_after.txt'), 'w', buffering = 0)
# svc_get_fb_log( engine, f_fblog_after )
# flush_and_close( f_fblog_after )
2021-11-16 19:44:53 +01:00
#
2021-04-26 20:07:00 +02:00
# # 07.08.2016
# # DIFFERENCE in the content of firebird.log should be EMPTY:
# ####################
2021-11-16 19:44:53 +01:00
#
2021-04-26 20:07:00 +02:00
# oldfb=open(f_fblog_before.name, 'r')
# newfb=open(f_fblog_after.name, 'r')
2021-11-16 19:44:53 +01:00
#
2021-04-26 20:07:00 +02:00
# difftext = ''.join(difflib.unified_diff(
2021-11-16 19:44:53 +01:00
# oldfb.readlines(),
2021-04-26 20:07:00 +02:00
# newfb.readlines()
# ))
# oldfb.close()
# newfb.close()
2021-11-16 19:44:53 +01:00
#
2021-04-26 20:07:00 +02:00
# f_diff_txt=open( os.path.join(context['temp_directory'],'tmp_2879_diff.txt'), 'w', buffering = 0)
# f_diff_txt.write(difftext)
# flush_and_close( f_diff_txt )
2021-11-16 19:44:53 +01:00
#
# # NB: difflib.unified_diff() can show line(s) that present in both files, without marking that line(s) with "+".
2021-04-26 20:07:00 +02:00
# # Usually these are 1-2 lines that placed just BEFORE difference starts.
# # So we have to check output before display diff content: lines that are really differ must start with "+".
2021-11-16 19:44:53 +01:00
#
2021-04-26 20:07:00 +02:00
# with open( f_diff_txt.name,'r') as f:
# for line in f:
# if line.startswith('+') and line.split('+'):
# print(line.replace('+',' '))
2021-11-16 19:44:53 +01:00
#
2021-04-26 20:07:00 +02:00
# # 01.02.2020. We have to change DB state to full shutdown and bring it back online
# # in order to prevent "Object in use" while fbtest will try to drop this DB
# #####################################
# runProgram('gfix',[dsn,'-shut','full','-force','0'])
# runProgram('gfix',[dsn,'-online'])
2021-11-16 19:44:53 +01:00
#
#
#
2021-04-26 20:07:00 +02:00
# # Cleanup:
# ##########
# time.sleep(1)
# cleanup( [i.name for i in (f_isql_cmd, f_isql_log, fbsvc_log, f_fblog_before,f_fblog_after, f_diff_txt)] )
2021-11-16 19:44:53 +01:00
#
#
2021-04-26 20:07:00 +02:00
#---
2021-11-16 19:44:53 +01:00
act_1 = python_act('db_1', substitutions=substitutions_1)
2021-04-26 20:07:00 +02:00
expected_stdout_1 = """
Sweep is started by SYSDBA
Sweep is finished
2021-11-16 19:44:53 +01:00
"""
isql_script = temp_file('test-script.sql')
2021-04-26 20:07:00 +02:00
@pytest.mark.version('>=2.5.1')
2021-11-16 19:44:53 +01:00
def test_1(act_1: Action, isql_script: Path, capsys):
isql_script.write_text(''' set list on;
set term ^;
execute block returns (dts timestamp, sql varchar(80)) as
declare i int;
declare s varchar(256);
begin
i = 1;
while (i < 32767) do
begin
s = 'tmp' || :i;
dts = 'now';
sql = 'create global temporary table ' || :s || ' (id int);';
execute statement sql with autonomous transaction;
suspend;
dts = 'now';
sql = 'drop table ' || :s || ';';
execute statement sql with autonomous transaction;
suspend;
i = i + 1;
end
end ^
set term ;^
''')
with act_1.connect_server() as srv:
# Get content of firebird.log BEFORE test
srv.info.get_log()
log_before = srv.readlines()
p_isql = subprocess.Popen([act_1.vars['isql'], act_1.db.dsn, '-i', str(isql_script)],
stderr=subprocess.STDOUT)
time.sleep(2)
# LAUNCH SWEEP while ISQL is working
srv.database.sweep(database=act_1.db.db_path)
2021-11-16 19:44:53 +01:00
p_isql.terminate()
# Get content of firebird.log AFTER test
srv.info.get_log()
log_after = srv.readlines()
for line in unified_diff(log_before, log_after):
if line.startswith('+') and line.split('+'):
print(line.replace('+', ' '))
act_1.expected_stdout = expected_stdout_1
act_1.stdout = capsys.readouterr().out
assert act_1.clean_stdout == act_1.clean_expected_stdout
2021-04-26 20:07:00 +02:00