Skip to content

Commit 22a1491

Browse files
author
v.shepard
committed
PBCKP-588 test partially fixed test_simple_remote.py 41/43
1 parent 2c2d2c5 commit 22a1491

File tree

4 files changed

+42
-18
lines changed

4 files changed

+42
-18
lines changed

testgres/node.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -519,8 +519,8 @@ def get_auth_method(t):
519519
u"local\treplication\tall\t\t\t{}\n".format(auth_local),
520520
u"host\treplication\tall\t127.0.0.1/32\t{}\n".format(auth_host),
521521
u"host\treplication\tall\t::1/128\t\t{}\n".format(auth_host),
522-
u"host\treplication\t{}\t{}/24\t\t{}\n".format(self.os_ops.username, subnet_base, auth_host),
523-
u"host\tall\t{}\t{}/24\t\t{}\n".format(self.os_ops.username, subnet_base, auth_host)
522+
u"host\treplication\tall\t{}/24\t\t{}\n".format(subnet_base, auth_host),
523+
u"host\tall\tall\t{}/24\t\t{}\n".format(subnet_base, auth_host)
524524
] # yapf: disable
525525

526526
# write missing lines
@@ -790,7 +790,9 @@ def restart(self, params=[]):
790790
] + params # yapf: disable
791791

792792
try:
793-
execute_utility(_params, self.utils_log_file)
793+
error_code, out, error = execute_utility(_params, self.utils_log_file, verbose=True)
794+
if 'could not start server' in error:
795+
raise ExecUtilException
794796
except ExecUtilException as e:
795797
msg = 'Cannot restart node'
796798
files = self._collect_special_files()

testgres/operations/remote_ops.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,17 @@ def __init__(self, host="127.0.0.1", hostname='localhost', port=None, ssh_key=No
4646
self.remote = True
4747
self.ssh = self.ssh_connect()
4848
self.username = username or self.get_user()
49+
self.tunnel = None
4950

5051
def __del__(self):
5152
if self.ssh:
5253
self.ssh.close()
54+
self.close_tunnel()
55+
56+
def close_tunnel(self):
57+
if self.tunnel:
58+
self.tunnel.stop(force=True)
59+
self.tunnel = None
5360

5461
def ssh_connect(self) -> Optional[SSHClient]:
5562
if not self.remote:
@@ -402,26 +409,27 @@ def db_connect(self, dbname, user, password=None, host="127.0.0.1", port=5432, s
402409
This function establishes a connection to a PostgreSQL database on the remote system using the specified
403410
parameters. It returns a connection object that can be used to interact with the database.
404411
"""
405-
tunnel = sshtunnel.open_tunnel(
412+
self.close_tunnel()
413+
self.tunnel = sshtunnel.open_tunnel(
406414
(host, 22), # Remote server IP and SSH port
407415
ssh_username=user or self.username,
408416
ssh_pkey=ssh_key or self.ssh_key,
409417
remote_bind_address=(host, port), # PostgreSQL server IP and PostgreSQL port
410418
local_bind_address=('localhost', port) # Local machine IP and available port
411419
)
412420

413-
tunnel.start()
421+
self.tunnel.start()
414422

415423
try:
416424
conn = pglib.connect(
417425
host=host, # change to 'localhost' because we're connecting through a local ssh tunnel
418-
port=tunnel.local_bind_port, # use the local bind port set up by the tunnel
426+
port=self.tunnel.local_bind_port, # use the local bind port set up by the tunnel
419427
dbname=dbname,
420428
user=user or self.username,
421429
password=password
422430
)
423431

424432
return conn
425433
except Exception as e:
426-
tunnel.stop()
434+
self.tunnel.stop()
427435
raise e

testgres/pubsub.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,4 +214,4 @@ def catchup(self, username=None):
214214
username=username or self.pub.username,
215215
max_attempts=LOGICAL_REPL_MAX_CATCHUP_ATTEMPTS)
216216
except Exception as e:
217-
raise_from(CatchUpException("Failed to catch up", query), e)
217+
raise_from(CatchUpException("Failed to catch up"), e)

tests/test_simple_remote.py

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import subprocess
77
import tempfile
88

9+
import pytest
910

1011
import testgres
1112
import time
@@ -59,6 +60,11 @@
5960
testgres_config.set_os_ops(os_ops=os_ops)
6061

6162

63+
@pytest.fixture
64+
def close_connections():
65+
yield os_ops.__del__()
66+
67+
6268
def pg_version_ge(version):
6369
cur_ver = PgVer(get_pg_version())
6470
min_ver = PgVer(version)
@@ -97,6 +103,11 @@ def get_remote_node():
97103
return get_new_node(host=os_ops.host, username=os_ops.username, ssh_key=os_ops.ssh_key)
98104

99105

106+
@pytest.fixture(scope="session", autouse=True)
107+
def close_connections():
108+
yield os_ops.__del__()
109+
110+
100111
class TestgresRemoteTests(unittest.TestCase):
101112

102113
def test_node_repr(self):
@@ -138,6 +149,7 @@ def test_init_after_cleanup(self):
138149
@unittest.skipUnless(util_exists('pg_resetwal'), 'might be missing')
139150
@unittest.skipUnless(pg_version_ge('9.6'), 'requires 9.6+')
140151
def test_init_unique_system_id(self):
152+
# FAIL
141153
# this function exists in PostgreSQL 9.6+
142154
query = 'select system_identifier from pg_control_system()'
143155

@@ -291,7 +303,7 @@ def test_psql(self):
291303
node.safe_psql('copy horns from stdin (format csv)',
292304
input=b"1\n2\n3\n\\.\n")
293305
_sum = node.safe_psql('select sum(w) from horns')
294-
self.assertEqual(b'6\n', _sum)
306+
self.assertEqual(_sum, b'6\n')
295307

296308
# check psql's default args, fails
297309
with self.assertRaises(QueryException):
@@ -688,6 +700,7 @@ def test_poll_query_until(self):
688700
node.poll_query_until('select true')
689701

690702
def test_logging(self):
703+
# FAIL
691704
logfile = tempfile.NamedTemporaryFile('w', delete=True)
692705

693706
log_conf = {
@@ -747,14 +760,11 @@ def test_pgbench(self):
747760
options=['-q']).pgbench_run(time=2)
748761

749762
# run TPC-B benchmark
750-
proc = node.pgbench(stdout=subprocess.PIPE,
763+
out = node.pgbench(stdout=subprocess.PIPE,
751764
stderr=subprocess.STDOUT,
752765
options=['-T3'])
753766

754-
out, _ = proc.communicate()
755-
out = out.decode('utf-8')
756-
757-
self.assertTrue('tps' in out)
767+
self.assertTrue(b'tps = ' in out)
758768

759769
def test_pg_config(self):
760770
# check same instances
@@ -819,12 +829,16 @@ def test_unix_sockets(self):
819829
node.init(unix_sockets=False, allow_streaming=True)
820830
node.start()
821831

822-
node.execute('select 1')
823-
node.safe_psql('select 1')
832+
res_exec = node.execute('select 1')
833+
res_psql = node.safe_psql('select 1')
834+
self.assertEqual(res_exec, [(1,)])
835+
self.assertEqual(res_psql, b'1\n')
824836

825837
with node.replicate().start() as r:
826-
r.execute('select 1')
827-
r.safe_psql('select 1')
838+
res_exec = r.execute('select 1')
839+
res_psql = r.safe_psql('select 1')
840+
self.assertEqual(res_exec, [(1,)])
841+
self.assertEqual(res_psql, b'1\n')
828842

829843
def test_auto_name(self):
830844
with get_remote_node().init(allow_streaming=True).start() as m:

0 commit comments

Comments
 (0)
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