|
1 | | -use std::sync::{Arc, Mutex}; |
| 1 | +use std::sync::{Arc, Mutex, OnceLock}; |
2 | 2 |
|
3 | 3 | use axum::extract::State; |
4 | 4 | use axum::routing::post; |
5 | 5 | use axum::{Json, Router}; |
6 | 6 | use serde_json::json; |
7 | 7 |
|
8 | | -static ENV_LOCK: Mutex<()> = Mutex::new(()); |
| 8 | +static ENV_LOCK: OnceLock<tokio::sync::Mutex<()>> = OnceLock::new(); |
| 9 | + |
| 10 | +fn env_lock() -> &'static tokio::sync::Mutex<()> { |
| 11 | + ENV_LOCK.get_or_init(|| tokio::sync::Mutex::new(())) |
| 12 | +} |
9 | 13 |
|
10 | 14 | #[derive(Clone, Default)] |
11 | 15 | struct TestState { |
@@ -109,9 +113,8 @@ async fn openai_compat_client_posts_and_parses_tool_calls() { |
109 | 113 | } |
110 | 114 |
|
111 | 115 | #[tokio::test] |
112 | | -#[allow(clippy::await_holding_lock)] |
113 | 116 | async fn openai_compat_client_retries_transient_http_errors() { |
114 | | - let _lock = ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner()); |
| 117 | + let _lock = env_lock().lock().await; |
115 | 118 | let _guard = EnvVarGuard::set("LOOPFORGE_LLM_RETRY_MAX", "1"); |
116 | 119 |
|
117 | 120 | async fn handler( |
@@ -244,9 +247,8 @@ async fn openai_compat_client_parses_legacy_function_call_into_tool_call() { |
244 | 247 | } |
245 | 248 |
|
246 | 249 | #[tokio::test] |
247 | | -#[allow(clippy::await_holding_lock)] |
248 | 250 | async fn openai_compat_client_timeout_can_be_overridden_via_env() { |
249 | | - let _lock = ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner()); |
| 251 | + let _lock = env_lock().lock().await; |
250 | 252 | let _guard = EnvVarGuard::set("LOOPFORGE_OPENAI_COMPAT_TIMEOUT_SECS", "1"); |
251 | 253 | let _retry_guard = EnvVarGuard::set("LOOPFORGE_LLM_RETRY_MAX", "0"); |
252 | 254 |
|
|
0 commit comments