fix(risk): fix circuit_breaker position_limit_zero_portfolio test
Replace RealBrokerClient (which connects to localhost:50054) with MockBrokerService in test, so it runs without a live broker. All 209 risk tests now pass. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -798,6 +798,36 @@ mod tests {
|
||||
use tokio;
|
||||
// CANONICAL TYPE IMPORTS - Use types::prelude for dec! macro
|
||||
|
||||
/// Mock broker service for unit tests that don't require a real broker connection
|
||||
struct MockBrokerService {
|
||||
portfolio_value: Decimal,
|
||||
daily_pnl: Decimal,
|
||||
}
|
||||
|
||||
impl MockBrokerService {
|
||||
fn with_zero_portfolio() -> Self {
|
||||
Self {
|
||||
portfolio_value: Decimal::ZERO,
|
||||
daily_pnl: Decimal::ZERO,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl BrokerAccountService for MockBrokerService {
|
||||
async fn get_portfolio_value(&self, _account_id: &str) -> RiskResult<Decimal> {
|
||||
Ok(self.portfolio_value)
|
||||
}
|
||||
|
||||
async fn get_daily_pnl(&self, _account_id: &str) -> RiskResult<Decimal> {
|
||||
Ok(self.daily_pnl)
|
||||
}
|
||||
|
||||
async fn get_positions(&self, _account_id: &str) -> RiskResult<Vec<Position>> {
|
||||
Ok(Vec::new())
|
||||
}
|
||||
}
|
||||
|
||||
fn create_test_config() -> Result<CircuitBreakerConfig, Box<dyn std::error::Error>> {
|
||||
Ok(CircuitBreakerConfig {
|
||||
enabled: true,
|
||||
@@ -876,7 +906,8 @@ mod tests {
|
||||
async fn test_circuit_breaker_position_limit_zero_portfolio(
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let config = create_test_config()?;
|
||||
let broker_service = Arc::new(RealBrokerClient::new("http://localhost:50054".to_string()));
|
||||
let broker_service: Arc<dyn BrokerAccountService> =
|
||||
Arc::new(MockBrokerService::with_zero_portfolio());
|
||||
|
||||
if let Ok(circuit_breaker) = RealCircuitBreaker::new(config, broker_service).await {
|
||||
let account_id = "TEST_ACCOUNT";
|
||||
|
||||
Reference in New Issue
Block a user