mod.rs 1.87 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
pub mod mock_worker;

use actix_web::web;
use reqwest::Client;
use sglang_router_rs::config::{PolicyConfig, RouterConfig, RoutingMode};
use sglang_router_rs::server::AppState;

/// Helper function to create test router configuration
pub fn create_test_config(worker_urls: Vec<String>) -> RouterConfig {
    RouterConfig {
        mode: RoutingMode::Regular { worker_urls },
        policy: PolicyConfig::Random,
        host: "127.0.0.1".to_string(),
        port: 3001,
        max_payload_size: 256 * 1024 * 1024, // 256MB
        request_timeout_secs: 600,
        worker_startup_timeout_secs: 300,
        worker_startup_check_interval_secs: 10,
        discovery: None,
        metrics: None,
        log_dir: None,
        log_level: None,
23
        request_id_headers: None,
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
    }
}

/// Helper function to create test router configuration with no health check
pub fn create_test_config_no_workers() -> RouterConfig {
    RouterConfig {
        mode: RoutingMode::Regular {
            worker_urls: vec![],
        }, // Empty to skip health check
        policy: PolicyConfig::Random,
        host: "127.0.0.1".to_string(),
        port: 3001,
        max_payload_size: 256 * 1024 * 1024, // 256MB
        request_timeout_secs: 600,
        worker_startup_timeout_secs: 0, // No wait
        worker_startup_check_interval_secs: 10,
        discovery: None,
        metrics: None,
        log_dir: None,
        log_level: None,
44
        request_id_headers: None,
45
46
47
48
49
50
51
52
53
54
55
56
57
58
    }
}

/// Helper function to create test app state
pub async fn create_test_app_state(config: RouterConfig) -> Result<web::Data<AppState>, String> {
    // Create a non-blocking client
    let client = Client::builder()
        .timeout(std::time::Duration::from_secs(config.request_timeout_secs))
        .build()
        .map_err(|e| e.to_string())?;

    let app_state = AppState::new(config, client)?;
    Ok(web::Data::new(app_state))
}