Keep native Qwen TTS resident after cooperative stream cancellation

This commit is contained in:
Mikei386 committed 2026-10-19 12:03:47 +02:00
1 parent 3435379ce0
commit 182c8a1e8f
6 files changed
+98 -14

No files matched your search

+21 -1
View File
@@ -1,4 +1,4 @@
import tempfile,unittest
import json,tempfile,unittest
from pathlib import Path
from unittest.mock import Mock,patch
from qwen_native import QwenNative
@@ -41,6 +41,26 @@ class NativeQwenTests(unittest.TestCase):
APIHandler.speech(h,ep,dict(model='tts',input='Ein synthetischer Satz.',response_format=fmt))
ep.qwen_native.start.assert_called_once();pocket.start.assert_not_called();ep.tts.start.assert_not_called()
self.assertEqual(ep.qwen_native.start.call_args.kwargs['streaming'],fmt=='pcm')
def test_cancelled_native_job_keeps_healthy_worker_and_releases_gate(self):
for policy,ok,expected_unload in (('warm',True,False),('auto',True,False),('per_request',True,True),('warm',False,True)):
with self.subTest(policy=policy,ok=ok),tempfile.TemporaryDirectory() as d:
worker=QwenNative(Path(d),Mock(),Mock());worker.policy=policy
ident='a'*32;job=Path(d)/ident;job.mkdir();(job/'chunk-000000.pcm').write_bytes(b'00')
(job/'result.json').write_text(json.dumps(dict(ok=ok,cancelled=True)))
process=Mock();process.poll.return_value=None;worker.process=process
worker._ensure_cpu=Mock(return_value=process);worker.unload_idle=Mock()
worker.job=dict(id=ident,state='running');worker.gate.acquire()
process.stdin.write.side_effect=lambda _:worker.cancel_job(ident)
worker._run_cpu({'id':'native'},ident,'Synthetischer Satz.',Path(d)/'reference.wav',True)
self.assertTrue((job/'cancel').exists())
self.assertEqual(worker.job['state'],'cancelled' if ok else 'failed')
self.assertEqual(worker.unload_idle.called,expected_unload)
self.assertFalse((job/'chunk-000000.pcm').exists());self.assertTrue(worker.gate.acquire(False));worker.gate.release()
if not expected_unload:self.assertIs(worker.process,process)
def test_cancel_does_not_signal_another_job(self):
with tempfile.TemporaryDirectory() as d:
worker=QwenNative(Path(d),Mock(),Mock());worker.job=dict(id='a'*32,state='running')
worker.cancel_job('b'*32);self.assertFalse(worker.cancel.is_set());self.assertFalse((Path(d)/('b'*32)).exists())
def test_native_warming_works_while_llm_queue_is_busy(self):
from audio_policy import AudioPolicy
from test_audio_policy import Worker,Profiles,Scheduler,AutoEndpoint