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

Commit1b4f74a

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

File tree

4 files changed

+44
-21
lines changed

4 files changed

+44
-21
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: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
importos
22
importtempfile
3+
importtime
34
fromtypingimportOptional
45

56
importsshtunnel
@@ -46,11 +47,29 @@ def __init__(self, host="127.0.0.1", hostname='localhost', port=None, ssh_key=No
4647
self.remote=True
4748
self.ssh=self.ssh_connect()
4849
self.username=usernameorself.get_user()
50+
self.tunnel=None
51+
52+
def__enter__(self):
53+
returnself
54+
55+
def__exit__(self,exc_type,exc_val,exc_tb):
56+
self.close_tunnel()
57+
ifgetattr(self,'ssh',None):
58+
self.ssh.close()
4959

5060
def__del__(self):
51-
ifself.ssh:
61+
ifgetattr(self,'ssh',None):
5262
self.ssh.close()
5363

64+
defclose_tunnel(self):
65+
ifgetattr(self,'tunnel',None):
66+
self.tunnel.stop(force=True)
67+
start_time=time.time()
68+
whileself.tunnel.is_active:
69+
iftime.time()-start_time>sshtunnel.TUNNEL_TIMEOUT:
70+
break
71+
time.sleep(0.5)
72+
5473
defssh_connect(self)->Optional[SSHClient]:
5574
ifnotself.remote:
5675
returnNone
@@ -402,26 +421,27 @@ def db_connect(self, dbname, user, password=None, host="127.0.0.1", port=5432, s
402421
This function establishes a connection to a PostgreSQL database on the remote system using the specified
403422
parameters. It returns a connection object that can be used to interact with the database.
404423
"""
405-
tunnel=sshtunnel.open_tunnel(
424+
self.close_tunnel()
425+
self.tunnel=sshtunnel.open_tunnel(
406426
(host,22),# Remote server IP and SSH port
407427
ssh_username=userorself.username,
408428
ssh_pkey=ssh_keyorself.ssh_key,
409429
remote_bind_address=(host,port),# PostgreSQL server IP and PostgreSQL port
410430
local_bind_address=('localhost',port)# Local machine IP and available port
411431
)
412432

413-
tunnel.start()
433+
self.tunnel.start()
414434

415435
try:
416436
conn=pglib.connect(
417437
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
438+
port=self.tunnel.local_bind_port,# use the local bind port set up by the tunnel
419439
dbname=dbname,
420440
user=userorself.username,
421441
password=password
422442
)
423443

424444
returnconn
425445
exceptExceptionase:
426-
tunnel.stop()
446+
self.tunnel.stop()
427447
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: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
importsubprocess
77
importtempfile
88

9-
109
importtestgres
1110
importtime
1211
importsix
@@ -138,6 +137,7 @@ def test_init_after_cleanup(self):
138137
@unittest.skipUnless(util_exists('pg_resetwal'),'might be missing')
139138
@unittest.skipUnless(pg_version_ge('9.6'),'requires 9.6+')
140139
deftest_init_unique_system_id(self):
140+
# FAIL
141141
# this function exists in PostgreSQL 9.6+
142142
query='select system_identifier from pg_control_system()'
143143

@@ -291,7 +291,7 @@ def test_psql(self):
291291
node.safe_psql('copy horns from stdin (format csv)',
292292
input=b"1\n2\n3\n\\.\n")
293293
_sum=node.safe_psql('select sum(w) from horns')
294-
self.assertEqual(b'6\n',_sum)
294+
self.assertEqual(_sum,b'6\n')
295295

296296
# check psql's default args, fails
297297
withself.assertRaises(QueryException):
@@ -688,6 +688,7 @@ def test_poll_query_until(self):
688688
node.poll_query_until('select true')
689689

690690
deftest_logging(self):
691+
# FAIL
691692
logfile=tempfile.NamedTemporaryFile('w',delete=True)
692693

693694
log_conf= {
@@ -747,14 +748,11 @@ def test_pgbench(self):
747748
options=['-q']).pgbench_run(time=2)
748749

749750
# run TPC-B benchmark
750-
proc=node.pgbench(stdout=subprocess.PIPE,
751+
out=node.pgbench(stdout=subprocess.PIPE,
751752
stderr=subprocess.STDOUT,
752753
options=['-T3'])
753754

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

759757
deftest_pg_config(self):
760758
# check same instances
@@ -764,7 +762,6 @@ def test_pg_config(self):
764762

765763
# save right before config change
766764
c1=get_pg_config()
767-
768765
# modify setting for this scope
769766
withscoped_config(cache_pg_config=False)asconfig:
770767

@@ -819,12 +816,16 @@ def test_unix_sockets(self):
819816
node.init(unix_sockets=False,allow_streaming=True)
820817
node.start()
821818

822-
node.execute('select 1')
823-
node.safe_psql('select 1')
819+
res_exec=node.execute('select 1')
820+
res_psql=node.safe_psql('select 1')
821+
self.assertEqual(res_exec, [(1,)])
822+
self.assertEqual(res_psql,b'1\n')
824823

825824
withnode.replicate().start()asr:
826-
r.execute('select 1')
827-
r.safe_psql('select 1')
825+
res_exec=r.execute('select 1')
826+
res_psql=r.safe_psql('select 1')
827+
self.assertEqual(res_exec, [(1,)])
828+
self.assertEqual(res_psql,b'1\n')
828829

829830
deftest_auto_name(self):
830831
withget_remote_node().init(allow_streaming=True).start()asm:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp