2121 CatchUpException , \
2222 TimeoutException
2323
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+
2637from 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
2952
3053
3154class SimpleTest (unittest .TestCase ):
@@ -87,12 +110,19 @@ def test_uninitialized_start(self):
87110 def test_restart (self ):
88111 with get_new_node ('test' ) as node :
89112 node .init ().start ()
113+
114+ # restart, ok
90115 res = node .execute ('postgres' , 'select 1' )
91116 self .assertEqual (res , [(1 , )])
92117 node .restart ()
93118 res = node .execute ('postgres' , 'select 2' )
94119 self .assertEqual (res , [(2 , )])
95120
121+ # restart, fail
122+ with self .assertRaises (StartNodeException ):
123+ node .append_conf ('pg_hba.conf' , 'DUMMY' )
124+ node .restart ()
125+
96126 def test_psql (self ):
97127 with get_new_node ('test' ) as node :
98128 node .init ().start ()
@@ -409,9 +439,7 @@ def test_poll_query_until(self):
409439
410440 # check ProgrammingError, fail
411441 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' )
415443
416444 # check ProgrammingError, ok
417445 with self .assertRaises (TimeoutException ):
@@ -471,6 +499,8 @@ def test_logging(self):
471499 master .restart ()
472500 self .assertTrue (master ._logger .is_alive ())
473501
502+ @unittest .skipUnless (
503+ util_is_executable ("pgbench" ), "pgbench may be missing" )
474504 def test_pgbench (self ):
475505 with get_new_node ('node' ) as node :
476506 node .init ().start ().pgbench_init ()
@@ -489,18 +519,17 @@ def test_reload(self):
489519 with get_new_node ('node' ) as node :
490520 node .init ().start ()
491521
492- cmd1 = "alter system set client_min_messages = DEBUG1"
493- cmd2 = "show client_min_messages"
522+ cmd = "show client_min_messages"
494523
495524 # 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' )
498527
499528 # reload config
500529 node .reload ()
501530
502531 # check new value
503- cmm_new = node .execute (dbname = 'postgres' , query = cmd2 )
532+ cmm_new = node .execute (dbname = 'postgres' , query = cmd )
504533 self .assertEqual ('debug1' , cmm_new [0 ][0 ].lower ())
505534 self .assertNotEqual (cmm_old , cmm_new )
506535
0 commit comments