fix(gateway): 修复 balance 刷新去重键冲突、usage 状态回退与测试竞态

- balance_cache: 引入实例级 refresh key 防止多实例共享进程级 HashSet 冲突
- InMemoryUsageRepo: 阻止 pending/streaming 状态覆盖已终结(completed/failed/cancelled)记录
- usage 同步测试: 等待条件从 is_some() 改为检查 status=="completed" 避免竞态
- wallet 测试: 增加轮询等待 wallet 扣款完成
- 整理 import 语句与 tests 模块位置
This commit is contained in:
fawney19
2026-04-13 16:48:05 +08:00
parent 9a376e4223
commit 4fd2b4a014
13 changed files with 266 additions and 70 deletions
@@ -111,7 +111,10 @@ async fn gateway_records_usage_for_execution_runtime_sync_when_runtime_enabled()
.find_by_request_id("req-usage-sync-123")
.await
.expect("usage lookup should succeed");
if stored.is_some() {
if stored
.as_ref()
.is_some_and(|usage| usage.status == "completed")
{
break;
}
tokio::time::sleep(std::time::Duration::from_millis(10)).await;