Skip to content

Commit 6eea5f1

Browse files
committed
chore: add tests
1 parent 24af905 commit 6eea5f1

4 files changed

Lines changed: 977 additions & 2 deletions

File tree

tests/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def test_something(mock_server):
2525
server = MockSSEServer(port=0) # Pick available port
2626
server.start()
2727
yield server
28+
# Stop the server (this will also disconnect clients)
2829
server.stop()
2930

3031

tests/mock_server.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import socketserver
1212
import threading
1313
import time
14-
from http.server import BaseHTTPRequestHandler, HTTPServer
14+
from http.server import BaseHTTPRequestHandler, HTTPServer, ThreadingHTTPServer
1515
from typing import Any
1616

1717

@@ -97,7 +97,7 @@ def do_POST(self) -> None:
9797
server.active_connections -= 1
9898

9999

100-
class MockSSEServer(HTTPServer):
100+
class MockSSEServer(ThreadingHTTPServer):
101101
"""Controllable HTTP server for testing SSE clients.
102102
103103
Example:
@@ -109,6 +109,9 @@ class MockSSEServer(HTTPServer):
109109
>>> server.stop()
110110
"""
111111

112+
# Use daemon threads so they don't block shutdown
113+
daemon_threads = True
114+
112115
def __init__(self, port: int = 0):
113116
"""Initialize the mock server.
114117
@@ -157,6 +160,7 @@ def start(self) -> None:
157160
def stop(self) -> None:
158161
"""Stop the server and wait for it to finish."""
159162
self.should_stop = True
163+
self.should_disconnect = True # Force active handlers to exit
160164
self.shutdown()
161165
if self._thread:
162166
self._thread.join(timeout=2.0)

0 commit comments

Comments
 (0)