Skip to content

Commit 9140b98

Browse files
committed
fix several incosistencies spotted by @Valeria1235
1 parent 24221e6 commit 9140b98

File tree

4 files changed

+36
-27
lines changed

4 files changed

+36
-27
lines changed

Diff for: testgres/connection.py

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
default_dbname, \
1818
default_username
1919

20-
2120
# export these exceptions
2221
InternalError = pglib.InternalError
2322
ProgrammingError = pglib.ProgrammingError

Diff for: testgres/node.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ def _format_verbose_error(self, message=None):
228228
def init(self,
229229
fsync=False,
230230
unix_sockets=True,
231-
allow_streaming=False,
231+
allow_streaming=True,
232232
initdb_params=[]):
233233
"""
234234
Perform initdb for this node.
@@ -401,7 +401,7 @@ def status(self):
401401

402402
def get_pid(self):
403403
"""
404-
Return postmaster's pid if node is running, else 0.
404+
Return postmaster's PID if node is running, else 0.
405405
"""
406406

407407
if self.status():
@@ -603,7 +603,7 @@ def cleanup(self, max_attempts=3):
603603

604604
return self
605605

606-
@method_decorator(positional_args_hack(['query'], ['dbname', 'query']))
606+
@method_decorator(positional_args_hack(['dbname', 'query']))
607607
def psql(self,
608608
query=None,
609609
filename=None,

Diff for: testgres/utils.py

+12-15
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@
2323

2424
def reserve_port():
2525
"""
26-
Generate a new port and add it to '_bound_ports'.
26+
Generate a new port and add it to 'bound_ports'.
2727
"""
2828

29-
global bound_ports
3029
port = port_for.select_random(exclude_ports=bound_ports)
3130
bound_ports.add(port)
3231

@@ -38,7 +37,6 @@ def release_port(port):
3837
Free port provided by reserve_port().
3938
"""
4039

41-
global bound_ports
4240
bound_ports.remove(port)
4341

4442

@@ -65,7 +63,7 @@ def generate_app_name():
6563
"""
6664

6765
import uuid
68-
return ''.join(['testgres-', str(uuid.uuid4())])
66+
return 'testgres-{}'.format(str(uuid.uuid4()))
6967

7068

7169
def execute_utility(args, logfile):
@@ -147,11 +145,7 @@ def get_pg_config():
147145
NOTE: this fuction caches the result by default (see TestgresConfig).
148146
"""
149147

150-
global _pg_config_data
151-
152148
def cache_pg_config_data(cmd):
153-
global _pg_config_data
154-
155149
# execute pg_config and get the output
156150
out = subprocess.check_output([cmd]).decode('utf-8')
157151

@@ -161,16 +155,19 @@ def cache_pg_config_data(cmd):
161155
key, _, value = line.partition('=')
162156
data[key.strip()] = value.strip()
163157

164-
_pg_config_data.clear()
165-
166-
# cache data, if necessary
167-
if TestgresConfig.cache_pg_config:
168-
_pg_config_data = data
158+
# cache data
159+
global _pg_config_data
160+
_pg_config_data = data
169161

170162
return data
171163

172-
# return cached data, if allowed to
173-
if TestgresConfig.cache_pg_config and _pg_config_data:
164+
# drop cache if asked to
165+
if not TestgresConfig.cache_pg_config:
166+
global _pg_config_data
167+
_pg_config_data = {}
168+
169+
# return cached data
170+
if _pg_config_data:
174171
return _pg_config_data
175172

176173
# try PG_CONFIG

Diff for: tests/test_simple.py

+21-8
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,20 @@
3838

3939

4040
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):
41+
def good_properties(f):
42+
return (
43+
os.path.exists(f) and
44+
os.path.isfile(f) and
45+
os.access(f, os.X_OK)
46+
)
47+
48+
# try to resolve it
49+
if good_properties(get_bin_path(util)):
4550
return True
4651

4752
# check if util is in PATH
4853
for path in os.environ["PATH"].split(os.pathsep):
49-
exe_file = os.path.join(path, util)
50-
if os.path.exists(exe_file):
54+
if good_properties(os.path.join(path, util)):
5155
return True
5256

5357

@@ -519,19 +523,28 @@ def test_pgbench(self):
519523

520524
self.assertTrue('tps' in out)
521525

522-
def test_config(self):
526+
def test_pg_config(self):
523527
# set global if it wasn't set
524-
configure_testgres(cache_initdb=True, cache_pg_config=True)
528+
configure_testgres(cache_pg_config=True)
525529

526530
# check same instances
527531
a = get_pg_config()
528532
b = get_pg_config()
529533
self.assertEqual(id(a), id(b))
530534

535+
# save right before config change
536+
c1 = get_pg_config()
537+
531538
# modify setting
532539
configure_testgres(cache_pg_config=False)
533540
self.assertFalse(TestgresConfig.cache_pg_config)
534541

542+
# save right after config change
543+
c2 = get_pg_config()
544+
545+
# check different instances after config change
546+
self.assertNotEqual(id(c1), id(c2))
547+
535548
# check different instances
536549
a = get_pg_config()
537550
b = get_pg_config()

0 commit comments

Comments
 (0)