Skip to content

NodeApp::make_simple is refactored (tempfile.gettempdir) #157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 51 additions & 18 deletions testgres/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import signal
import subprocess
import threading
import tempfile
from queue import Queue

import time
Expand Down Expand Up @@ -1761,6 +1762,8 @@ def make_simple(
pg_options={},
checksum=True,
bin_dir=None):
assert type(pg_options) == dict # noqa: E721

if checksum and '--data-checksums' not in initdb_params:
initdb_params.append('--data-checksums')
node = self.make_empty(base_dir, port, bin_dir=bin_dir)
Expand All @@ -1773,20 +1776,22 @@ def make_simple(
node.major_version = float(node.major_version_str)

# Set default parameters
options = {'max_connections': 100,
'shared_buffers': '10MB',
'fsync': 'off',
'wal_level': 'logical',
'hot_standby': 'off',
'log_line_prefix': '%t [%p]: [%l-1] ',
'log_statement': 'none',
'log_duration': 'on',
'log_min_duration_statement': 0,
'log_connections': 'on',
'log_disconnections': 'on',
'restart_after_crash': 'off',
'autovacuum': 'off',
'unix_socket_directories': '/tmp'}
options = {
'max_connections': 100,
'shared_buffers': '10MB',
'fsync': 'off',
'wal_level': 'logical',
'hot_standby': 'off',
'log_line_prefix': '%t [%p]: [%l-1] ',
'log_statement': 'none',
'log_duration': 'on',
'log_min_duration_statement': 0,
'log_connections': 'on',
'log_disconnections': 'on',
'restart_after_crash': 'off',
'autovacuum': 'off',
# unix_socket_directories will be defined later
}

# Allow replication in pg_hba.conf
if set_replication:
Expand All @@ -1801,11 +1806,16 @@ def make_simple(
else:
options['wal_keep_segments'] = '12'

# set default values
node.set_auto_conf(options)

# Apply given parameters
node.set_auto_conf(pg_options)
for option_name, option_value in iteritems(pg_options):
options[option_name] = option_value

# Define delayed propertyes
if not ("unix_socket_directories" in options.keys()):
options["unix_socket_directories"] = __class__._gettempdir()

# Set config values
node.set_auto_conf(options)

# kludge for testgres
# https://github.com/postgrespro/testgres/issues/54
Expand All @@ -1814,3 +1824,26 @@ def make_simple(
node.set_auto_conf({}, 'postgresql.conf', ['wal_keep_segments'])

return node

def _gettempdir():
v = tempfile.gettempdir()

#
# Paranoid checks
#
if type(v) != str: # noqa: E721
__class__._raise_bugcheck("tempfile.gettempdir returned a value with type {0}.".format(type(v).__name__))

if v == "":
__class__._raise_bugcheck("tempfile.gettempdir returned an empty string.")

if not os.path.exists(v):
__class__._raise_bugcheck("tempfile.gettempdir returned a not exist path [{0}].".format(v))

# OK
return v

def _raise_bugcheck(msg):
assert type(msg) == str # noqa: E721
assert msg != ""
raise Exception("[BUG CHECK] " + msg)