Skip to content

Commit 8f7d779

Browse files
committed
Added/Updated tests\functional\replication\test_oltp_emul_ddl.py: Added code for running test when no port is specified in the firebird-driver.conf and it has default (commented) value in the firebird.conf. Added check that port is actually listening. Replaced hard-coded SYSDBA/masterkey -- see notes.
1 parent f236cd9 commit 8f7d779

File tree

1 file changed

+50
-10
lines changed

1 file changed

+50
-10
lines changed

tests/functional/replication/test_oltp_emul_ddl.py

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,23 @@
3434
Temporary DISABLED execution on Linux when ServerMode = Classic. Replication can unexpectedly stop with message
3535
'Engine is shutdown' appears in replication.log. Sent report to dimitr, waiting for fix.
3636
37-
Checked on 4.0.3.2931, 5.0.0.1022, both SS and CS.
37+
Checked on Windows 4.0.3.2931, 5.0.0.1022, SS and CS.
38+
39+
[07.09.2023] pzotov
40+
Added 'DEBUG_MODE' variable for quick switch to debug branches if something goes wrong.
41+
Added code to explicitly assign 'fb_port' to default value (3050), with check that port is listening (see 'import socket')
42+
Replaced hardcoded 'SYSDBA' and 'masterkey' with act.db.user and act.db.password
43+
(see call of generate_sync_settings_sql() and its code)
44+
45+
Checked on Linux 5.0.0.1190 CS with default firebird.conf and firebird-driver.conf without port specifying
46+
(see letters from dimitr, 06.09.2023)
3847
"""
3948

4049
import os
4150
import locale
4251
import shutil
4352
import zipfile
53+
import socket
4454
from difflib import unified_diff
4555
from pathlib import Path
4656
import time
@@ -49,6 +59,8 @@
4959
from firebird.qa import *
5060
from firebird.driver import connect, create_database, DbWriteMode, ReplicaMode, ShutdownMode, ShutdownMethod, DatabaseError
5161

62+
DEBUG_MODE = 0
63+
5264
# QA_GLOBALS -- dict, is defined in qa/plugin.py, obtain settings
5365
# from act.files_dir/'test_config.ini':
5466
repl_settings = QA_GLOBALS['replication']
@@ -311,7 +323,7 @@ def drop_db_objects(act_db_main: Action, act_db_repl: Action, capsys):
311323

312324
#--------------------------------------------
313325

314-
def generate_sync_settings_sql(db_main_file_name, fb_port):
326+
def generate_sync_settings_sql(db_main_file_name, dba_usr, dba_psw, fb_port = 3050):
315327

316328
def generate_inject_setting_sql(working_mode, mcode, new_value, allow_insert_if_eof = 0):
317329
sql_inject_setting = ''
@@ -350,7 +362,7 @@ def generate_inject_setting_sql(working_mode, mcode, new_value, allow_insert_if_
350362
sql_adjust_settings_table = ''.join( (sql_adjust_settings_table, generate_inject_setting_sql( 'common', 'separate_workers', "'1'" ) ) )
351363
sql_adjust_settings_table = ''.join( (sql_adjust_settings_table, generate_inject_setting_sql( 'common', 'workers_count', "'100'" ) ) )
352364
sql_adjust_settings_table = ''.join( (sql_adjust_settings_table, generate_inject_setting_sql( 'common', 'update_conflict_percent', "'0'" ) ) )
353-
sql_adjust_settings_table = ''.join( (sql_adjust_settings_table, generate_inject_setting_sql( 'init', 'connect_str', "'connect ''localhost:%(db_main_file_name)s'' user ''SYSDBA'' password ''masterkey'';'" % locals(), 1 ) ) )
365+
sql_adjust_settings_table = ''.join( (sql_adjust_settings_table, generate_inject_setting_sql( 'init', 'connect_str', "'connect ''localhost:%(db_main_file_name)s'' user ''%(dba_usr)s'' password ''%(dba_psw)s'';'" % locals(), 1 ) ) )
354366

355367
sql_adjust_settings_table = ''.join( (sql_adjust_settings_table, generate_inject_setting_sql( 'common', 'mon_unit_list', "'//'" ) ) )
356368
sql_adjust_settings_table = ''.join( (sql_adjust_settings_table, generate_inject_setting_sql( 'common', 'halt_test_on_errors', "'/PK/CK/'" ) ) )
@@ -367,8 +379,8 @@ def generate_inject_setting_sql(working_mode, mcode, new_value, allow_insert_if_
367379
sql_adjust_settings_table = ''.join( (sql_adjust_settings_table, generate_inject_setting_sql( 'common', 'use_es', "'2'", 1 ) ) )
368380
sql_adjust_settings_table = ''.join( (sql_adjust_settings_table, generate_inject_setting_sql( 'init', 'host', "'localhost'", 1 ) ) )
369381
sql_adjust_settings_table = ''.join( (sql_adjust_settings_table, generate_inject_setting_sql( 'init', 'port', "'%(fb_port)s'" % locals(), 1 ) ) )
370-
sql_adjust_settings_table = ''.join( (sql_adjust_settings_table, generate_inject_setting_sql( 'init', 'usr', "'SYSDBA'", 1 ) ) )
371-
sql_adjust_settings_table = ''.join( (sql_adjust_settings_table, generate_inject_setting_sql( 'init', 'pwd', "'masterkey'", 1 ) ) )
382+
sql_adjust_settings_table = ''.join( (sql_adjust_settings_table, generate_inject_setting_sql( 'init', 'usr', "'%(dba_usr)s'" % locals(), 1 ) ) )
383+
sql_adjust_settings_table = ''.join( (sql_adjust_settings_table, generate_inject_setting_sql( 'init', 'pwd', "'%(dba_psw)s'" % locals(), 1 ) ) )
372384
sql_adjust_settings_table = ''.join( (sql_adjust_settings_table, generate_inject_setting_sql( 'init', 'tmp_worker_user_pswd', "'0Ltp-Emu1'", 1 ) ) )
373385

374386
sql_adjust_settings_table = ''.join( (sql_adjust_settings_table, generate_inject_setting_sql( 'init', 'conn_pool_support', "'1'", 1 ) ) )
@@ -417,6 +429,25 @@ def test_1(act_db_main: Action, act_db_repl: Action, tmp_oltp_build_sql: Path,
417429
repl_log_old = get_replication_log(act_db_main)
418430
repl_log_new = repl_log_old.copy()
419431

432+
# NB, 06-sep-2023: we have to explicitly assign default value for listening port because OLTP-EMUL requires it always.
433+
# If $QA_HOME/firebird-driver.conf does not contain line with this parameter then act_db_main.port will be None.
434+
# In that case execution of some scripts will fail because of conversion error from string 'None' to int variable.
435+
# This problem was detected for script 'oltp-emul-09_adjust_eds_calls.sql':
436+
# declare v_port int;
437+
# ...
438+
# select ... max( iif( upper(s.mcode) = upper('port'), s.svalue , null ) )
439+
# from settings s
440+
# where ...
441+
# into v_port ... ; <<< THIS WILL FAIL with 'conversion error from "None"'.
442+
443+
fb_port = 3050
444+
if act_db_main.port:
445+
fb_port = int(act_db_main.port) if act_db_main.port.isdigit() else fb_port
446+
447+
# Additional check: fb_port must be listening now:
448+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
449+
s.connect(('localhost', fb_port))
450+
420451
# Must be EMPTY:
421452
out_prep = capsys.readouterr().out
422453
if out_prep:
@@ -432,7 +463,7 @@ def test_1(act_db_main: Action, act_db_repl: Action, tmp_oltp_build_sql: Path,
432463
#--------------------------------------------------------------------------------
433464
with open(tmp_oltp_build_sql, 'w') as f:
434465
f.write( sql_build_init )
435-
f.write( generate_sync_settings_sql(db_info[act_db_main, 'db_full_path'], act_db_main.port) )
466+
f.write( generate_sync_settings_sql(db_info[act_db_main, 'db_full_path'], act_db_main.db.user, act_db_main.db.password, fb_port) )
436467
#--------------------------------------------------------------------------------
437468

438469
oltp_post_files = tmp_oltp_sql_files[5:10] # 'oltp-emul-06_split_heavy_tabs.sql' ... 'oltp-emul-10_adjust_eds_perf.sql'
@@ -480,15 +511,20 @@ def test_1(act_db_main: Action, act_db_repl: Action, tmp_oltp_build_sql: Path,
480511

481512
act_db_main.reset()
482513

483-
for p in tmp_oltp_sql_files:
484-
p.unlink(missing_ok = True)
514+
if DEBUG_MODE:
515+
pass
516+
else:
517+
for p in tmp_oltp_sql_files:
518+
p.unlink(missing_ok = True)
485519

486520
repl_log_new = get_replication_log(act_db_main)
487521

488522
if out_prep:
489523
# Some problem raised during execution of initial SQL
490524
pass
491525
else:
526+
527+
492528
# Query to be used for check that all DB objects present in replica (after last DML statement completed on master DB):
493529
ddl_ready_query = "select 1 from rdb$relations where rdb$relation_name = upper('t_completed')"
494530

@@ -517,15 +553,19 @@ def test_1(act_db_main: Action, act_db_repl: Action, tmp_oltp_build_sql: Path,
517553
out_main = capsys.readouterr().out
518554
repl_log_new = get_replication_log(act_db_main)
519555

520-
drop_db_objects(act_db_main, act_db_repl, capsys)
556+
if DEBUG_MODE:
557+
pass
558+
else:
559+
drop_db_objects(act_db_main, act_db_repl, capsys)
560+
521561
# Must be EMPTY:
522562
out_drop = capsys.readouterr().out
523563

524564
if [ x for x in (out_prep, out_main, out_drop) if x.strip() ]:
525565
# We have a problem either with DDL/DML or with dropping DB objects.
526566
# First, we have to RECREATE both master and slave databases
527567
# (otherwise further execution of this test or other replication-related tests most likely will fail):
528-
out_reset = reset_replication(act_db_main, act_db_repl, db_info[act_db_main,'db_full_path'], db_info[act_db_repl,'db_full_path'], cleanup_repl_dirs = True)
568+
out_reset = reset_replication(act_db_main, act_db_repl, db_info[act_db_main,'db_full_path'], db_info[act_db_repl,'db_full_path'], cleanup_repl_dirs = not DEBUG_MODE)
529569

530570
# Next, we display out_main, out_drop and out_reset:
531571
#

0 commit comments

Comments
 (0)