Skip to content

Commit 0e3a50e

Browse files
committed
fix tests for 9.4
1 parent 53c79f5 commit 0e3a50e

File tree

4 files changed

+52
-22
lines changed

4 files changed

+52
-22
lines changed

testgres/backup.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,14 @@ def __init__(self,
4848
self._available = True
4949

5050
data_dir = os.path.join(self.base_dir, _DATA_DIR)
51+
52+
# yapf: disable
5153
_params = [
5254
get_bin_path("pg_basebackup"),
53-
"-D{}".format(data_dir), "-p{}".format(node.port),
54-
"-U{}".format(username), "-X{}".format(xlog_method)
55+
"-p", str(node.port),
56+
"-U", username,
57+
"-D", data_dir,
58+
"-X", xlog_method
5559
]
5660
_execute_utility(_params, self.log_file)
5761

testgres/node.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -352,12 +352,10 @@ def get_control_data(self):
352352
Return contents of pg_control file.
353353
"""
354354

355-
# yapf: disable
356-
_params = [
357-
get_bin_path("pg_controldata"),
358-
"-D" if _pg_version_ge('9.5') else '',
359-
self.data_dir
360-
]
355+
# this one is tricky (blame PG 9.4)
356+
_params = [get_bin_path("pg_controldata")]
357+
_params += ["-D"] if _pg_version_ge('9.5') else []
358+
_params += [self.data_dir]
361359

362360
data = _execute_utility(_params, self.utils_log_name)
363361

testgres/utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from .config import TestgresConfig
1111
from .exceptions import ExecUtilException
1212

13-
1413
# rows returned by PG_CONFIG
1514
_pg_config_data = {}
1615

@@ -72,7 +71,7 @@ def execute_utility(args, logfile):
7271

7372
# run utility
7473
process = subprocess.Popen(
75-
args, # util + params
74+
args, # util + params
7675
stdout=subprocess.PIPE,
7776
stderr=subprocess.STDOUT)
7877

tests/test_simple.py

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,34 @@
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+
2637
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
2952

3053

3154
class 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

Comments
 (0)