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

159 lines
4.8 KiB
Python
Raw Normal View History

2021-04-26 20:07:00 +02:00
#coding:utf-8
#
# id: bugs.core_5434
# title: Read-only transactions in SuperServer could avoid immediate write of Header and TIP pages after change
# decription:
2021-04-26 20:07:00 +02:00
# If current FB arch is SuperServer then we:
# 1. We make 'snapshot' of mon$io_stats.mon$page_writes value before test and then launch plently transactions (e.g, 50)
2021-04-26 20:07:00 +02:00
# in READ-ONLY mode. All of them then are immediately committed, w/o any actions.
# 2. After this we take 2nd 'snapshot' of mon$io_stats.mon$page_writes and compare it with 1st one.
# 3. Difference of 'mon$page_writes' values should be 1 (One).
# Otherwise (SC/CS) we defer checking because improvement currently not implemented for these modes.
#
2021-04-26 20:07:00 +02:00
# Checked on:
# 1) WI-T4.0.0.463, WI-V3.0.2.32670 - room for improvement DOES exist: page_diff = 102 pages
# 2) WI-T4.0.0.511, WI-V3.0.2.32676 - all OK, page_diff = 1 (One).
#
2021-04-26 20:07:00 +02:00
# tracker_id: CORE-5434
# min_versions: ['3.0.2']
# versions: 3.0.2
# qmid: None
import pytest
from firebird.qa import db_factory, python_act, Action
from firebird.driver import TraAccessMode, TPB
2021-04-26 20:07:00 +02:00
# version: 3.0.2
# resources: None
#substitutions_1 = [('Deferred: fb_arch=.*', 'Acceptable')]
substitutions_1 = []
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-04-26 20:07:00 +02:00
# import os
# import sys
# os.environ["ISC_USER"] = user_name
# os.environ["ISC_PASSWORD"] = user_password
#
2021-04-26 20:07:00 +02:00
# def get_fb_arch(a_dsn):
# try:
# con1 = fdb.connect(dsn = a_dsn)
# con2 = fdb.connect(dsn = a_dsn)
#
2021-04-26 20:07:00 +02:00
# cur1 = con1.cursor()
#
2021-04-26 20:07:00 +02:00
# sql=(
# "select count(distinct a.mon$server_pid), min(a.mon$remote_protocol), max(iif(a.mon$remote_protocol is null,1,0))"
# +" from mon$attachments a"
# +" where a.mon$attachment_id in (%s, %s) or upper(a.mon$user) = upper('%s')"
# % (con1.attachment_id, con2.attachment_id, 'cache writer')
# )
#
2021-04-26 20:07:00 +02:00
# cur1.execute(sql)
# for r in cur1.fetchall():
# server_cnt=r[0]
# server_pro=r[1]
# cache_wrtr=r[2]
#
2021-04-26 20:07:00 +02:00
# if server_pro == None:
# fba='Embedded'
# elif cache_wrtr == 1:
# fba='SS'
# elif server_cnt == 2:
# fba='CS'
# else:
#
2021-04-26 20:07:00 +02:00
# f1=con1.db_info(fdb.isc_info_fetches)
#
2021-04-26 20:07:00 +02:00
# cur2=con2.cursor()
# cur2.execute('select 1 from rdb$database')
# for r in cur2.fetchall():
# pass
#
2021-04-26 20:07:00 +02:00
# f2=con1.db_info(fdb.isc_info_fetches)
#
2021-04-26 20:07:00 +02:00
# fba = 'SC' if f1 ==f2 else 'SS'
#
2021-04-26 20:07:00 +02:00
# #print(fba, con1.engine_version, con1.version)
# return fba
#
2021-04-26 20:07:00 +02:00
# finally:
# con1.close()
# con2.close()
#
2021-04-26 20:07:00 +02:00
# fb_arch=get_fb_arch(dsn)
#
2021-04-26 20:07:00 +02:00
# if fb_arch == 'SS':
#
2021-04-26 20:07:00 +02:00
# txParams = ( [ fdb.isc_tpb_read ] )
# c2 = fdb.connect(dsn=dsn)
#
2021-04-26 20:07:00 +02:00
# sql='select mon$page_writes from mon$io_stats where mon$stat_group=0'
# cur=db_conn.cursor()
#
2021-04-26 20:07:00 +02:00
# cur.execute(sql)
# for r in cur:
# page_writes_before_test = r[0]
# db_conn.commit()
#
2021-04-26 20:07:00 +02:00
# ta=[]
# for i in range(0, 50):
# ta.append( c2.trans( default_tpb = txParams ) )
# ta[i].begin()
#
2021-04-26 20:07:00 +02:00
# for i in range(0,len(ta)):
# ta[i].rollback()
#
#
2021-04-26 20:07:00 +02:00
# cur.execute(sql)
# for r in cur:
# page_writes_after_test = r[0]
#
2021-04-26 20:07:00 +02:00
# pw_diff = page_writes_after_test - page_writes_before_test
#
2021-04-26 20:07:00 +02:00
# db_conn.commit()
# c2.close()
#
2021-04-26 20:07:00 +02:00
# msg = 'Acceptable' if pw_diff == 1 else ('Too big value of page_writes diff: %s' % ( pw_diff ))
# else:
# # FB works NOT in SuperServer. This currently must be SKIPPED from checking (see notes in the ticket).
# msg = 'Deferred: fb_arch=%s' % fb_arch
#
2021-04-26 20:07:00 +02:00
# print(msg)
#
#
2021-04-26 20:07:00 +02:00
#---
act_1 = python_act('db_1', substitutions=substitutions_1)
2021-04-26 20:07:00 +02:00
@pytest.mark.version('>=3.0.2')
def test_1(act_1: Action):
tpb = TPB(access_mode=TraAccessMode.READ).get_buffer()
sql = 'select mon$page_writes from mon$io_stats where mon$stat_group=0'
if act_1.get_server_architecture() == 'SS':
with act_1.db.connect() as con:
with act_1.db.connect() as con2:
cur = con.cursor()
page_writes_before_test = cur.execute(sql).fetchone()[0]
con.commit()
#
ta = []
for i in range(50):
tra = con2.transaction_manager(default_tpb=tpb)
tra.begin()
ta.append(tra)
for tra in ta:
tra.rollback()
#
cur = con.cursor()
page_writes_after_test = cur.execute(sql).fetchone()[0]
con.commit()
#
assert page_writes_after_test - page_writes_before_test == 1