Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement to random port allocation for redis testing #591

Merged
merged 3 commits into from
May 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions tests/clients/redis/test_redis.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import string
from random import randint

from jumpscale.loader import j
from parameterized import parameterized
Expand All @@ -11,7 +10,7 @@
class RedisTests(BaseTests):
def setUp(self):
self.redis_instance_name = self.randstr()
self.port = randint(20000, 21000)
self.port = j.sals.nettools.get_free_port()

def tearDown(self):
self.redis_client.flushall()
Expand Down
13 changes: 6 additions & 7 deletions tests/sals/process/test_process.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import string
import getpass
from math import ceil
from random import randint
from gevent import sleep

import pytest
Expand Down Expand Up @@ -308,10 +307,10 @@ def test_10_get_filtered_pids(self):
- Check that only one server is found.
"""
self.info("Start a tmux session with two python server process.")
port_1 = randint(20000, 21000)
port_2 = randint(22000, 23000)
port_1 = j.sals.nettools.get_free_port()
cmd = f"python3 -m {PYTHON_SERVER_NAME} {port_1}"
self.start_in_tmux(cmd)
port_2 = j.sals.nettools.get_free_port()
cmd = f"python3 -m {PYTHON_SERVER_NAME} {port_2}"
self.start_in_tmux(cmd)
self.assertTrue(j.sals.nettools.wait_connection_test(HOST, port_1, 2))
Expand Down Expand Up @@ -383,7 +382,7 @@ def test_12_get_processes_info(self):
- Check that this process in processes self.info.
"""
self.info("Start python server in tmux.")
port = randint(10000, 20000)
port = j.sals.nettools.get_free_port()
cmd = f"python3 -m {PYTHON_SERVER_NAME} {port}"
self.start_in_tmux(cmd)
self.assertTrue(j.sals.nettools.wait_connection_test(HOST, port, 2))
Expand Down Expand Up @@ -431,7 +430,7 @@ def test_13_get_kill_process_by_port(self):
- Check that the server pid is not exist.
"""
self.info("Start python server in tmux.")
port = randint(10000, 20000)
port = j.sals.nettools.get_free_port()
cmd = f"python3 -m {PYTHON_SERVER_NAME} {port}"
self.start_in_tmux(cmd)
self.assertTrue(j.sals.nettools.wait_connection_test(HOST, port, 2))
Expand Down Expand Up @@ -657,7 +656,7 @@ def test_20_get_ports_mapping(self):
- Check that the result from both ways are the same.
"""
self.info("Start python server.")
python_port = randint(10000, 20000)
python_port = j.sals.nettools.get_free_port()
cmd = f"python3 -m {PYTHON_SERVER_NAME} {python_port}"
self.start_in_tmux(cmd)
self.assertTrue(j.sals.nettools.wait_connection_test(HOST, python_port, 2))
Expand All @@ -668,7 +667,7 @@ def test_20_get_ports_mapping(self):

self.info("Start redis server.")
process_name = "redis-server"
redis_port = randint(2001, 3000)
redis_port = j.sals.nettools.get_free_port()
cmd = f"{process_name} --port {redis_port}"
self.start_in_tmux(cmd)
self.assertTrue(j.sals.nettools.wait_connection_test(HOST, redis_port, 2))
Expand Down