From 6acbeb6517b6b4aac4d23f0a137821ddb6b7928f Mon Sep 17 00:00:00 2001 From: "d.kovalenko" Date: Fri, 6 Dec 2024 12:32:55 +0300 Subject: [PATCH 1/3] NodeApp::make_simple is refactored (tempfile.gettempdir) - [BUG FIX] Windows does not have "/tmp" directory. Let's use tempfile.gettempdir() - Aggregation of standard and custom options to avoid two calls of node.set_auto_conf --- testgres/node.py | 69 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 51 insertions(+), 18 deletions(-) diff --git a/testgres/node.py b/testgres/node.py index 1706de11..0e5bb866 100644 --- a/testgres/node.py +++ b/testgres/node.py @@ -5,6 +5,7 @@ import signal import subprocess import threading +import tempfile from queue import Queue import time @@ -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) @@ -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': '/tmp', + } # Allow replication in pg_hba.conf if set_replication: @@ -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 x in pg_options: + options[x] = pg_options[x] + + # 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 @@ -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) From 9d6f61472817c47477561911c7361d713a1fb1ca Mon Sep 17 00:00:00 2001 From: "d.kovalenko" Date: Fri, 6 Dec 2024 15:22:16 +0300 Subject: [PATCH 2/3] NodeApp::make_simple is updated [comment] --- testgres/node.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testgres/node.py b/testgres/node.py index 0e5bb866..62509790 100644 --- a/testgres/node.py +++ b/testgres/node.py @@ -1790,7 +1790,7 @@ def make_simple( 'log_disconnections': 'on', 'restart_after_crash': 'off', 'autovacuum': 'off', - # 'unix_socket_directories': '/tmp', + # unix_socket_directories will be defined later } # Allow replication in pg_hba.conf From 1d44628c65ad9266f303ecbb21080ed790ff01d0 Mon Sep 17 00:00:00 2001 From: "d.kovalenko" Date: Fri, 6 Dec 2024 15:47:20 +0300 Subject: [PATCH 3/3] NodeApp::make_simple uses iteritems(pg_options) --- testgres/node.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testgres/node.py b/testgres/node.py index 62509790..48a100a9 100644 --- a/testgres/node.py +++ b/testgres/node.py @@ -1807,8 +1807,8 @@ def make_simple( options['wal_keep_segments'] = '12' # Apply given parameters - for x in pg_options: - options[x] = pg_options[x] + 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()): pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy