hydro2_async_scheduler/
validate_network.rs

1// ---------------- [ File: src/validate_network.rs ]
2crate::ix!();
3
4/// Validates the network by locking it and invoking `validate()`.
5/// Returns an error if validation fails.
6pub async fn validate_network<T>(
7    network: &Arc<AsyncMutex<Network<T>>>,
8) -> Result<(), NetworkError>
9where
10    T: Debug + Send + Sync,
11{
12    let net_guard = network.lock().await;
13    eprintln!("execute_network: Validate network with {} nodes", net_guard.nodes().len());
14    net_guard.validate()?;
15    Ok(())
16}
17
18#[cfg(test)]
19mod validate_network_tests {
20    use super::*;
21
22    #[test]
23    fn test_validate_network_ok() {
24        let rt = TokioRuntime::new().unwrap();
25        rt.block_on(async {
26            // Mock a network with valid structure
27            let network = Arc::new(AsyncMutex::new(mock_valid_network()));
28            let res = validate_network(&network).await;
29            assert!(res.is_ok());
30        });
31    }
32    
33    // Helper stubs
34    fn mock_valid_network() -> Network<u32> {
35        // Construct a minimal valid network
36        let mut net = Network::default();
37        // ... set up valid nodes/edges ...
38        net
39    }
40}