From 2fa81dcce9e7b9abcaaa77c16360f89b450f8616 Mon Sep 17 00:00:00 2001 From: Sameh Abouel-saad Date: Wed, 12 May 2021 14:21:46 +0200 Subject: [PATCH 1/3] fix: Making the process of picking an available port Error-proofing when runs the Redis tests - using nettools sal instaed of the python `random` module --- tests/clients/redis/test_redis.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/clients/redis/test_redis.py b/tests/clients/redis/test_redis.py index b081bc886..e04a41ef0 100644 --- a/tests/clients/redis/test_redis.py +++ b/tests/clients/redis/test_redis.py @@ -11,7 +11,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() From 005f188ea85cd150157e7a9c151b12246df37f24 Mon Sep 17 00:00:00 2001 From: Sameh Abouel-saad Date: Mon, 17 May 2021 15:33:41 +0200 Subject: [PATCH 2/3] fix: fix same issue in process tests --- tests/sals/process/test_process.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/tests/sals/process/test_process.py b/tests/sals/process/test_process.py index 55015ea46..085ce07ef 100644 --- a/tests/sals/process/test_process.py +++ b/tests/sals/process/test_process.py @@ -1,7 +1,6 @@ import string import getpass from math import ceil -from random import randint from gevent import sleep import pytest @@ -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)) @@ -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)) @@ -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)) @@ -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)) @@ -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)) From 0872b4269802a4aa20ca02cd574ea1c507fa99c6 Mon Sep 17 00:00:00 2001 From: Sameh Abouel-saad Date: Mon, 17 May 2021 15:37:05 +0200 Subject: [PATCH 3/3] refactor: Removing unused import from test_redis.py --- tests/clients/redis/test_redis.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/clients/redis/test_redis.py b/tests/clients/redis/test_redis.py index e04a41ef0..327a2ad18 100644 --- a/tests/clients/redis/test_redis.py +++ b/tests/clients/redis/test_redis.py @@ -1,5 +1,4 @@ import string -from random import randint from jumpscale.loader import j from parameterized import parameterized