Skip to content

Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.

C++

serve tests: put the StopStrings and ConnectionClose classes back together after a merge (#715)

Niko122182579827e922
diff --git a/serve/test_server.py b/serve/test_server.py
index de6fc3c32..4130ede1d 100644
--- a/serve/test_server.py
+++ b/serve/test_server.py
@@ -3396,20 +3396,11 @@ class StopStrings(unittest.TestCase):
across tokens (and across streamed chunks)."""
ANSWER = "alpha END beta STOP gamma"
-
-class ConnectionClose(unittest.TestCase):
- """The server is HTTP/1.0 and closes the connection after every response. Without saying so, .NET's pooled
- HttpClient put its next request on the closing socket and got "response ended prematurely" (2026-10-03)."""
-
@classmethod
def setUpClass(cls):
tok = ByteTokenizer()
cls.engine = CountingEngine(tok, "</think>\n\n" + cls.ANSWER, max_context=CTX)
cls.svc = Service(cls.engine, tok, ChatTemplate(ROOT / "serve/chat_template.jinja"))
-
-
- cls.svc = Service(MockEngine(tok, "</think>\n\nok", max_context=CTX), tok,
- ChatTemplate(ROOT / "serve/chat_template.jinja"))
cls.httpd = serve(cls.svc, port=0)
cls.base = f"http://127.0.0.1:{cls.httpd.server_address[1]}"
@@ -3517,6 +3508,38 @@ class ConnectionClose(unittest.TestCase):
self.assertEqual(m.push("more"), "")
+class ConnectionClose(unittest.TestCase):
+ """The server is HTTP/1.0 and closes the connection after every response. Without saying so, .NET's pooled
+ HttpClient put its next request on the closing socket and got "response ended prematurely" (2026-10-03)."""
+
+ @classmethod
+ def setUpClass(cls):
+ tok = ByteTokenizer()
+ cls.svc = Service(MockEngine(tok, "</think>\n\nok", max_context=CTX), tok,
+ ChatTemplate(ROOT / "serve/chat_template.jinja"))
+ cls.httpd = serve(cls.svc, port=0)
+ cls.base = f"http://127.0.0.1:{cls.httpd.server_address[1]}"
+
+ @classmethod
+ def tearDownClass(cls):
+ cls.httpd.shutdown()
+ cls.httpd.server_close()
+
+ def headers(self, stream):
+ body = {"model": "x", "max_tokens": 20, "messages": [{"role": "user", "content": "hi"}], "stream": stream}
+ req = urllib.request.Request(self.base + "/v1/chat/completions", data=json.dumps(body).encode(),
+ headers={"Content-Type": "application/json"})
+ with urllib.request.urlopen(req, timeout=30) as r:
+ r.read()
+ return r.headers
+
+ def test_a_non_streamed_answer_says_the_connection_closes(self):
+ self.assertEqual(self.headers(stream=False).get("Connection"), "close")
+
+ def test_a_streamed_answer_says_the_connection_closes(self):
+ self.assertEqual(self.headers(stream=True).get("Connection"), "close")
+
+
class AnswerBeforeTheBody(unittest.TestCase):
"""An answer sent before the request body was read must still reach a client that sends the body after the headers
(http.client, urllib and requests do): closing the connection on unread bytes sends a reset that eats the answer."""
@@ -3614,25 +3637,6 @@ class AnswerBeforeTheBody(unittest.TestCase):
self.assertEqual(self.status("PUT", "/v1/chat/completions"), "HTTP/1.0 501 Unsupported method ('PUT')")
- def headers(self, stream):
- body = {"model": "x", "max_tokens": 20, "messages": [{"role": "user", "content": "hi"}], "stream": stream}
- req = urllib.request.Request(self.base + "/v1/chat/completions", data=json.dumps(body).encode(),
- headers={"Content-Type": "application/json"})
- with urllib.request.urlopen(req, timeout=30) as r:
- r.read()
- return r.headers
-
- def test_a_non_streamed_answer_says_the_connection_closes(self):
- self.assertEqual(self.headers(stream=False).get("Connection"), "close")
-
- def test_a_streamed_answer_says_the_connection_closes(self):
- self.assertEqual(self.headers(stream=True).get("Connection"), "close")
-
-
-if __name__ == "__main__":
- unittest.main()
-
-
class PromptProgressBatch(unittest.TestCase):
"""#837: under --batch the engine's progress is one global line: prompt_progress() says nothing."""
@@ -3672,3 +3676,7 @@ class VisionArgs(unittest.TestCase):
self.assertNotIn("--min-tokens", base)
self.assertEqual(self.args_for({"max_tokens": 1024, "min_tokens": 768})[-4:],
["--max-tokens", "1024", "--min-tokens", "768"])
+
+
+if __name__ == "__main__":
+ unittest.main()