Skip to content

Commit 5b27f27

Browse files
Fixed server and client shutdown for tests
1 parent 62ab5be commit 5b27f27

3 files changed

Lines changed: 29 additions & 0 deletions

File tree

CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ All notable changes to this project will be documented in this file.
66

77
### Changed
88

9+
#### 2026-01-13
10+
11+
* `./tests/base.py`: Added close method for `MockClient` to properly shutdown the client.
12+
* `./tests/test_managesieve.py`: Fixed `tearDown` methods to shutdown the client and the server properly.
13+
914
#### 2025-12-05
1015

1116
* `./pysieved/main.py`: Added file-based logging with `WatchedFileHandler` and removed syslog usage.

tests/base.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,15 @@ def __init__(self, server: Server) -> None:
9999
self.conn.settimeout(self._default_timeout)
100100
self.conn.connect((address, port))
101101

102+
def close(self) -> None:
103+
"""Terminate client."""
104+
105+
try:
106+
self.conn.shutdown(socket.SHUT_RDWR)
107+
self.conn.close()
108+
except Exception:
109+
pass
110+
102111
def get_full_response(self) -> bytes:
103112
"""Read all the received lines until the server stops responding until the timeout."""
104113

@@ -110,6 +119,9 @@ def get_full_response(self) -> bytes:
110119
except Exception:
111120
break
112121

122+
if not part:
123+
break
124+
113125
full_response += part
114126

115127
return full_response

tests/test_managesieve.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,13 @@ def setUp(self) -> None:
4343
self.password = "12345"
4444

4545
def tearDown(self) -> None:
46+
try:
47+
self.client.logout()
48+
finally:
49+
self.client.close()
50+
4651
self.server.shutdown()
52+
self.server.server_close()
4753
self._t.join()
4854

4955
super().tearDown()
@@ -110,7 +116,13 @@ def tearDownClass(cls) -> None:
110116
# if not removed:
111117
# warnings.warn(f"Could not remove filter '{cls.filter_name}'.")
112118

119+
try:
120+
cls.client.logout()
121+
finally:
122+
cls.client.close()
123+
113124
cls.server.shutdown()
125+
cls.server.server_close()
114126
cls._t.join()
115127

116128
super().tearDownClass()

0 commit comments

Comments
 (0)