21
21
CatchUpException , \
22
22
TimeoutException
23
23
24
- from testgres import TestgresConfig
25
- from testgres import get_new_node , get_pg_config , configure_testgres
24
+ from testgres import \
25
+ TestgresConfig , \
26
+ configure_testgres
27
+
28
+ from testgres import \
29
+ NodeStatus , \
30
+ IsolationLevel , \
31
+ get_new_node
32
+
33
+ from testgres import \
34
+ get_bin_path , \
35
+ get_pg_config
36
+
26
37
from testgres import bound_ports
27
- from testgres import NodeStatus
28
- from testgres import IsolationLevel
38
+
39
+
40
+ def util_is_executable (util ):
41
+ exe_file = get_bin_path (util )
42
+
43
+ # check if util exists
44
+ if os .path .exists (exe_file ):
45
+ return True
46
+
47
+ # check if util is in PATH
48
+ for path in os .environ ["PATH" ].split (os .pathsep ):
49
+ exe_file = os .path .join (path , util )
50
+ if os .path .exists (exe_file ):
51
+ return True
29
52
30
53
31
54
class SimpleTest (unittest .TestCase ):
@@ -87,12 +110,19 @@ def test_uninitialized_start(self):
87
110
def test_restart (self ):
88
111
with get_new_node ('test' ) as node :
89
112
node .init ().start ()
113
+
114
+ # restart, ok
90
115
res = node .execute ('postgres' , 'select 1' )
91
116
self .assertEqual (res , [(1 , )])
92
117
node .restart ()
93
118
res = node .execute ('postgres' , 'select 2' )
94
119
self .assertEqual (res , [(2 , )])
95
120
121
+ # restart, fail
122
+ with self .assertRaises (StartNodeException ):
123
+ node .append_conf ('pg_hba.conf' , 'DUMMY' )
124
+ node .restart ()
125
+
96
126
def test_psql (self ):
97
127
with get_new_node ('test' ) as node :
98
128
node .init ().start ()
@@ -409,9 +439,7 @@ def test_poll_query_until(self):
409
439
410
440
# check ProgrammingError, fail
411
441
with self .assertRaises (testgres .ProgrammingError ):
412
- node .poll_query_until (
413
- dbname = 'postgres' ,
414
- query = 'dummy1' )
442
+ node .poll_query_until (dbname = 'postgres' , query = 'dummy1' )
415
443
416
444
# check ProgrammingError, ok
417
445
with self .assertRaises (TimeoutException ):
@@ -471,6 +499,8 @@ def test_logging(self):
471
499
master .restart ()
472
500
self .assertTrue (master ._logger .is_alive ())
473
501
502
+ @unittest .skipUnless (
503
+ util_is_executable ("pgbench" ), "pgbench may be missing" )
474
504
def test_pgbench (self ):
475
505
with get_new_node ('node' ) as node :
476
506
node .init ().start ().pgbench_init ()
@@ -489,18 +519,17 @@ def test_reload(self):
489
519
with get_new_node ('node' ) as node :
490
520
node .init ().start ()
491
521
492
- cmd1 = "alter system set client_min_messages = DEBUG1"
493
- cmd2 = "show client_min_messages"
522
+ cmd = "show client_min_messages"
494
523
495
524
# change client_min_messages and save old value
496
- cmm_old = node .execute (dbname = 'postgres' , query = cmd2 )
497
- node .safe_psql ( dbname = 'postgres ' , query = cmd1 )
525
+ cmm_old = node .execute (dbname = 'postgres' , query = cmd )
526
+ node .append_conf ( 'postgresql.conf ' , 'client_min_messages = DEBUG1' )
498
527
499
528
# reload config
500
529
node .reload ()
501
530
502
531
# check new value
503
- cmm_new = node .execute (dbname = 'postgres' , query = cmd2 )
532
+ cmm_new = node .execute (dbname = 'postgres' , query = cmd )
504
533
self .assertEqual ('debug1' , cmm_new [0 ][0 ].lower ())
505
534
self .assertNotEqual (cmm_old , cmm_new )
506
535
0 commit comments