Skip to content

Commit 3a5067a

Browse files
authored
Merge pull request #42 from livestreamx/task-BQA-2593
logging port allocation fix
2 parents 94dcdee + d1ce025 commit 3a5067a

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

overhave/storage/emulation_storage.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,19 @@ def get_allocated_ports(self) -> List[int]:
9595
return [port for port, _ in port_user_pairs]
9696

9797
def get_allocated_port_user_pairs(self) -> List[List[int]]:
98-
return cast(List[List[int]], orjson.loads(cast(bytes, self._redis.get(self._settings.redis_ports_key))))
98+
allocated_port_user_pairs = cast(bytes | None, self._redis.get(self._settings.redis_ports_key))
99+
logger.debug("allocated port user pairs: %s", allocated_port_user_pairs)
100+
if allocated_port_user_pairs is None:
101+
return []
102+
return cast(List[List[int]], orjson.loads(allocated_port_user_pairs))
99103

100104
def allocate_port_for_user(self, port: int, test_user_id: int) -> None:
101105
new_allocated_ports = self.get_allocated_port_user_pairs()
106+
if [port, test_user_id] in new_allocated_ports:
107+
logger.debug("port %s for user %s already in redis: %s", port, test_user_id, new_allocated_ports)
108+
return
102109
new_allocated_ports.append([port, test_user_id])
110+
logger.debug("added port %s for user %s in redis: %s", port, test_user_id, new_allocated_ports)
103111
self._redis.set(self._settings.redis_ports_key, orjson.dumps(sorted(new_allocated_ports)))
104112

105113
def _is_port_in_use(self, port: int) -> bool:

0 commit comments

Comments
 (0)