Skip to content

Commit 7ee74cd

Browse files
committed
For tests, explicitly disable replication and conditionally perform check for crypt.
Tests are executed against databases in clusters that have restrained resources. Replication being enabled was triggering failures with the current configuration. Having the crypt user unconditionally created was causing errors in more recent versions of PostgreSQL. Only check crypt with now unsupported versions.
1 parent 8e3c229 commit 7ee74cd

3 files changed

Lines changed: 44 additions & 32 deletions

File tree

postgresql/temporal.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ def init(self,
110110
'could not find the default pg_config', details = inshint
111111
)
112112

113+
vi = installation.version_info
113114
cluster = Cluster(installation, self.cluster_path,)
114115

115116
# If it exists already, destroy it.
@@ -130,13 +131,18 @@ def init(self,
130131
creator = cluster
131132
)
132133

134+
if vi[:2] > (9,6):
135+
# Default changed in 10.x
136+
cluster.settings['max_wal_senders'] = '0'
137+
133138
cluster.settings.update(dict(
134139
port = str(self.cluster_port),
135140
max_connections = '20',
136141
shared_buffers = '200',
137142
listen_addresses = 'localhost',
138143
log_destination = 'stderr',
139144
log_min_messages = 'FATAL',
145+
max_prepared_transactions = '10',
140146
))
141147

142148
if installation.version_info[:2] < (9, 3):
@@ -148,10 +154,6 @@ def init(self,
148154
unix_socket_directories = cluster.data_directory,
149155
))
150156

151-
cluster.settings.update(dict(
152-
max_prepared_transactions = '10',
153-
))
154-
155157
# Start it up.
156158
with open(self.logfile, 'w') as lfo:
157159
cluster.start(logfile = lfo)

postgresql/test/test_cluster.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,15 @@ def start_cluster(self, logfile = None):
3030
def init(self, *args, **kw):
3131
self.cluster.init(*args, **kw)
3232

33-
if self.cluster.installation.version_info[:2] >= (9, 3):
33+
vi = self.cluster.installation.version_info[:2]
34+
if vi >= (9, 3):
3435
usd = 'unix_socket_directories'
3536
else:
3637
usd = 'unix_socket_directory'
3738

39+
if vi > (9, 6):
40+
self.cluster.settings['max_wal_senders'] = '0'
41+
3842
self.cluster.settings.update({
3943
'max_connections' : '8',
4044
'listen_addresses' : 'localhost',

postgresql/test/test_connect.py

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def __init__(self, *args, **kw):
5151
super().__init__(*args, **kw)
5252
self.installation = installation.default()
5353
self.cluster_path = \
54-
'py_unittest_pg_cluster_' \
54+
'pypg_test_' \
5555
+ str(os.getpid()) + getattr(self, 'cluster_path_suffix', '')
5656

5757
if self.installation is None:
@@ -68,6 +68,8 @@ def __init__(self, *args, **kw):
6868
if self.cluster.initialized():
6969
self.cluster.drop()
7070

71+
self.disable_replication = self.installation.version_info[:2] > (9, 6)
72+
7173
def configure_cluster(self):
7274
self.cluster_port = find_available_port()
7375
if self.cluster_port is None:
@@ -79,6 +81,7 @@ def configure_cluster(self):
7981
listen_addresses = '127.0.0.1'
8082
if has_ipv6:
8183
listen_addresses += ',::1'
84+
8285
self.cluster.settings.update(dict(
8386
port = str(self.cluster_port),
8487
max_connections = '6',
@@ -88,6 +91,11 @@ def configure_cluster(self):
8891
log_min_messages = 'FATAL',
8992
))
9093

94+
if self.disable_replication:
95+
self.cluster.settings.update({
96+
'max_wal_senders': '0',
97+
})
98+
9199
if self.cluster.installation.version_info[:2] < (9, 3):
92100
self.cluster.settings.update(dict(
93101
unix_socket_directory = self.cluster.data_directory,
@@ -157,30 +165,43 @@ class test_connect(TestCaseWithCluster):
157165
params = {}
158166
cluster_path_suffix = '_test_connect'
159167

168+
mk_common_users = """
169+
CREATE USER md5 WITH ENCRYPTED PASSWORD 'md5_password';
170+
CREATE USER password WITH ENCRYPTED PASSWORD 'password_password';
171+
CREATE USER trusted;
172+
"""
173+
174+
mk_crypt_user = """
175+
-- crypt doesn't work with encrypted passwords:
176+
-- http://www.postgresql.org/docs/8.2/interactive/auth-methods.html#AUTH-PASSWORD
177+
CREATE USER crypt WITH UNENCRYPTED PASSWORD 'crypt_password';
178+
"""
179+
160180
def __init__(self, *args, **kw):
161181
super().__init__(*args,**kw)
162182
# 8.4 nixed this.
163-
self.do_crypt = self.cluster.installation.version_info < (8,4)
183+
vi = self.cluster.installation.version_info
184+
self.check_crypt_user = (vi < (8,4))
164185

165186
def configure_cluster(self):
166187
super().configure_cluster()
167-
self.cluster.settings.update({
168-
'log_min_messages' : 'log',
169-
})
188+
self.cluster.settings['log_min_messages'] = 'log'
170189

171190
# Configure the hba file with the supported methods.
172191
with open(self.cluster.hba_file, 'w') as hba:
173192
hosts = ['0.0.0.0/0',]
174193
if has_ipv6:
175194
hosts.append('0::0/0')
176-
methods = ['md5', 'password'] + (['crypt'] if self.do_crypt else [])
195+
196+
methods = ['md5', 'password'] + (['crypt'] if self.check_crypt_user else [])
177197
for h in hosts:
178198
for m in methods:
179199
# user and method are the same name.
180200
hba.writelines(['host test {m} {h} {m}\n'.format(
181201
h = h,
182202
m = m
183203
)])
204+
184205
# trusted
185206
hba.writelines(["local all all trust\n"])
186207
hba.writelines(["host test trusted 0.0.0.0/0 trust\n"])
@@ -193,26 +214,11 @@ def configure_cluster(self):
193214

194215
def initialize_database(self):
195216
super().initialize_database()
217+
196218
with self.cluster.connection(user = 'test') as db:
197-
db.execute(
198-
"""
199-
CREATE USER md5 WITH
200-
ENCRYPTED PASSWORD 'md5_password'
201-
;
202-
203-
-- crypt doesn't work with encrypted passwords:
204-
-- http://www.postgresql.org/docs/8.2/interactive/auth-methods.html#AUTH-PASSWORD
205-
CREATE USER crypt WITH
206-
UNENCRYPTED PASSWORD 'crypt_password'
207-
;
208-
209-
CREATE USER password WITH
210-
ENCRYPTED PASSWORD 'password_password'
211-
;
212-
213-
CREATE USER trusted;
214-
"""
215-
)
219+
db.execute(self.mk_common_users)
220+
if self.check_crypt_user:
221+
db.execute(self.mk_crypt_user)
216222

217223
def test_pg_open_SQL_ASCII(self):
218224
# postgresql.open
@@ -364,7 +370,7 @@ def test_dbapi_connect(self):
364370
MD5.cursor().execute, 'select 1'
365371
)
366372

367-
if self.do_crypt:
373+
if self.check_crypt_user:
368374
CRYPT = dbapi20.connect(
369375
user = 'crypt',
370376
database = 'test',
@@ -449,7 +455,7 @@ def test_md5_connect(self):
449455
self.assertEqual(c.prepare('select current_user').first(), 'md5')
450456

451457
def test_crypt_connect(self):
452-
if self.do_crypt:
458+
if self.check_crypt_user:
453459
c = self.cluster.connection(
454460
user = 'crypt',
455461
password = 'crypt_password',

0 commit comments

Comments
 (0)