mirror of
https://github.com/beetbox/beets.git
synced 2026-02-14 11:24:39 +01:00
bpd tests: close only existing sockets
Close sockets in `finally`-clauses only after they have actually been created.
This commit is contained in:
parent
fb07a5112a
commit
871f79c8f2
1 changed files with 17 additions and 11 deletions
|
|
@ -324,19 +324,25 @@ class BPDTestHelper(unittest.TestCase, TestHelper):
|
|||
)
|
||||
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
sock.connect((host, port))
|
||||
try:
|
||||
sock.connect((host, port))
|
||||
|
||||
sock2 = None
|
||||
if second_client:
|
||||
sock2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
sock2.connect((host, port))
|
||||
yield MPCClient(sock, do_hello), MPCClient(sock2, do_hello)
|
||||
else:
|
||||
yield MPCClient(sock, do_hello)
|
||||
if second_client:
|
||||
sock2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
try:
|
||||
sock2.connect((host, port))
|
||||
yield (
|
||||
MPCClient(sock, do_hello),
|
||||
MPCClient(sock2, do_hello),
|
||||
)
|
||||
finally:
|
||||
sock2.close()
|
||||
|
||||
else:
|
||||
yield MPCClient(sock, do_hello)
|
||||
finally:
|
||||
sock.close()
|
||||
finally:
|
||||
sock.close()
|
||||
if sock2:
|
||||
sock2.close()
|
||||
server.terminate()
|
||||
server.join(timeout=0.2)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue