fix resource leaks in qmp tests

This commit is contained in:
Jörg Thalheim
2024-10-01 19:59:58 +02:00
parent 2f38955066
commit 8b205c78bf
4 changed files with 103 additions and 87 deletions

View File

@@ -1,7 +1,6 @@
import base64
import json
import socket
from pathlib import Path
from time import sleep
from clan_cli.errors import ClanError
@@ -12,17 +11,8 @@ from clan_cli.errors import ClanError
# - no need to initialize by asking for capabilities
# - results need to be base64 decoded
class QgaSession:
def __init__(self, socket_file: Path | str) -> None:
self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
# try to reconnect a couple of times if connection refused
for _ in range(100):
try:
self.sock.connect(str(socket_file))
except ConnectionRefusedError:
sleep(0.1)
else:
return
self.sock.connect(str(socket_file))
def __init__(self, sock: socket.socket) -> None:
self.sock = sock
def get_response(self) -> dict:
result = self.sock.recv(9999999)