Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit22a1491

Browse files
author
v.shepard
committed
PBCKP-588 test partially fixed test_simple_remote.py 41/43
1 parent2c2d2c5 commit22a1491

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'inerror:
795+
raiseExecUtilException
794796
exceptExecUtilExceptionase:
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=usernameorself.get_user()
49+
self.tunnel=None
4950

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

5461
defssh_connect(self)->Optional[SSHClient]:
5562
ifnotself.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=userorself.username,
408416
ssh_pkey=ssh_keyorself.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=userorself.username,
421429
password=password
422430
)
423431

424432
returnconn
425433
exceptExceptionase:
426-
tunnel.stop()
434+
self.tunnel.stop()
427435
raisee

‎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=usernameorself.pub.username,
215215
max_attempts=LOGICAL_REPL_MAX_CATCHUP_ATTEMPTS)
216216
exceptExceptionase:
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
importsubprocess
77
importtempfile
88

9+
importpytest
910

1011
importtestgres
1112
importtime
@@ -59,6 +60,11 @@
5960
testgres_config.set_os_ops(os_ops=os_ops)
6061

6162

63+
@pytest.fixture
64+
defclose_connections():
65+
yieldos_ops.__del__()
66+
67+
6268
defpg_version_ge(version):
6369
cur_ver=PgVer(get_pg_version())
6470
min_ver=PgVer(version)
@@ -97,6 +103,11 @@ def get_remote_node():
97103
returnget_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+
defclose_connections():
108+
yieldos_ops.__del__()
109+
110+
100111
classTestgresRemoteTests(unittest.TestCase):
101112

102113
deftest_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
deftest_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
withself.assertRaises(QueryException):
@@ -688,6 +700,7 @@ def test_poll_query_until(self):
688700
node.poll_query_until('select true')
689701

690702
deftest_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'inout)
767+
self.assertTrue(b'tps = 'inout)
758768

759769
deftest_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
withnode.replicate().start()asr:
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
deftest_auto_name(self):
830844
withget_remote_node().init(allow_streaming=True).start()asm:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp