fix: cancel Foundry prepare with provider
This commit is contained in:
1 parent
a54ca77e9b
commit
3d4d82f23d
2 files changed
+32
-5
No files matched your search
@@ -130,6 +130,8 @@ impl FoundryLocalWhisperAsr {
|
||||
|
||||
pub fn cancel(&self) {
|
||||
self.cancel_generation.fetch_add(1, Ordering::SeqCst);
|
||||
#[cfg(target_os = "windows")]
|
||||
self.runtime.request_cancel_prepare();
|
||||
self.buffer.lock().clear();
|
||||
}
|
||||
}
|
||||
@@ -241,13 +243,20 @@ mod tests {
|
||||
use crate::recorder::AudioConsumer;
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
fn test_provider() -> super::FoundryLocalWhisperAsr {
|
||||
fn test_provider() -> (
|
||||
super::FoundryLocalWhisperAsr,
|
||||
std::sync::Arc<super::FoundryLocalRuntime>,
|
||||
) {
|
||||
use std::sync::Arc;
|
||||
|
||||
super::FoundryLocalWhisperAsr::new(
|
||||
Arc::new(super::FoundryLocalRuntime::new()),
|
||||
"whisper-small".into(),
|
||||
Some(" zh ".into()),
|
||||
let runtime = Arc::new(super::FoundryLocalRuntime::new());
|
||||
(
|
||||
super::FoundryLocalWhisperAsr::new(
|
||||
Arc::clone(&runtime),
|
||||
"whisper-small".into(),
|
||||
Some(" zh ".into()),
|
||||
),
|
||||
runtime,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -301,6 +310,9 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn foundry_provider_cancel_clears_buffer() {
|
||||
#[cfg(target_os = "windows")]
|
||||
let (provider, _) = test_provider();
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
let provider = test_provider();
|
||||
|
||||
provider.consume_pcm_chunk(&[1, 0, 2, 0]);
|
||||
@@ -316,4 +328,14 @@ mod tests {
|
||||
assert_eq!(provider.model_alias(), "whisper-small");
|
||||
assert_eq!(provider.language_hint(), Some("zh"));
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
#[test]
|
||||
fn foundry_provider_cancel_requests_runtime_prepare_cancel() {
|
||||
let (provider, runtime) = test_provider();
|
||||
|
||||
provider.cancel();
|
||||
|
||||
assert!(runtime.cancel_prepare_requested_for_tests());
|
||||
}
|
||||
}
|
||||
@@ -99,6 +99,11 @@ mod imp {
|
||||
self.cancel_prepare.store(true, Ordering::SeqCst);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) fn cancel_prepare_requested_for_tests(&self) -> bool {
|
||||
self.cancel_prepare.load(Ordering::SeqCst)
|
||||
}
|
||||
|
||||
pub async fn catalog_snapshot(&self) -> Result<Vec<FoundryCatalogModel>> {
|
||||
let _lifecycle = self.lifecycle.lock().await;
|
||||
let manager = self.manager()?;
|
||||
|
||||
Reference in new issue
Block a user