Skip to content

Commit f28b71b

Browse files
committed
Use random port for each server instance in testing to avoid conflicts
1 parent 3fc3049 commit f28b71b

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

tests/test_pssh_client.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
import gevent
77
from gevent import monkey
88
monkey.patch_all()
9-
from pssh import ParallelSSHClient, UnknownHostException
9+
from pssh import ParallelSSHClient, UnknownHostException, ConnectionErrorException
1010
from paramiko import AuthenticationException
1111
from fake_server.fake_server import listen
12+
import random
1213

1314
class ParallelSSHClientTest(unittest.TestCase):
1415

@@ -17,18 +18,21 @@ def setUp(self):
1718
self.fake_resp = 'fake response'
1819

1920
def test_pssh_client_exec_command(self):
20-
server = gevent.spawn(listen, { self.fake_cmd : self.fake_resp })
21-
client = ParallelSSHClient(['localhost'], port = 2200)
21+
listen_port = random.randint(1025, 65534)
22+
server = gevent.spawn(listen, { self.fake_cmd : self.fake_resp }, listen_port = listen_port)
23+
client = ParallelSSHClient(['localhost'], port = listen_port)
2224
cmd = client.exec_command(self.fake_cmd)[0]
2325
output = client.get_stdout(cmd)
2426
expected = {'localhost' : {'exit_code' : 0}}
2527
self.assertEqual(expected, output, msg = "Got unexpected command output - %s" % (output,))
2628
server.kill()
2729

2830
def test_pssh_client_auth_failure(self):
29-
server = gevent.spawn(listen, { self.fake_cmd : self.fake_resp }, listen_port = 2201, fail_auth = True)
30-
client = ParallelSSHClient(['localhost'], port = 2201)
31+
listen_port = random.randint(1025, 65534)
32+
server = gevent.spawn(listen, { self.fake_cmd : self.fake_resp }, listen_port = listen_port, fail_auth = True)
33+
client = ParallelSSHClient(['localhost'], port = listen_port)
3134
try:
3235
cmd = client.exec_command(self.fake_cmd)[0]
3336
except AuthenticationException:
3437
pass
38+
server.kill()

0 commit comments

Comments
 (0)