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

logging port allocation fix #42

Merged
merged 1 commit into from
Feb 29, 2024
Merged
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
10 changes: 9 additions & 1 deletion overhave/storage/emulation_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,19 @@ def get_allocated_ports(self) -> List[int]:
return [port for port, _ in port_user_pairs]

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

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

def _is_port_in_use(self, port: int) -> bool:
Expand Down
Loading