mockforge_chaos/
protocols.rs

1//! Protocol-specific chaos engineering modules
2
3pub mod graphql;
4pub mod grpc;
5pub mod websocket;
6
7use crate::{ChaosConfig, Result};
8use async_trait::async_trait;
9
10/// Protocol-agnostic chaos trait
11#[async_trait]
12pub trait ChaosProtocol: Send + Sync {
13    /// Apply chaos before processing a request
14    async fn apply_pre_request(&self) -> Result<()>;
15
16    /// Apply chaos after processing a response
17    async fn apply_post_response(&self, response_size: usize) -> Result<()>;
18
19    /// Check if chaos should abort the request
20    fn should_abort(&self) -> Option<String>;
21
22    /// Get protocol name
23    fn protocol_name(&self) -> &str;
24}
25
26/// Common chaos operations for all protocols
27pub struct ProtocolChaos {
28    config: ChaosConfig,
29}
30
31impl ProtocolChaos {
32    pub fn new(config: ChaosConfig) -> Self {
33        Self { config }
34    }
35
36    pub fn config(&self) -> &ChaosConfig {
37        &self.config
38    }
39
40    pub fn is_enabled(&self) -> bool {
41        self.config.enabled
42    }
43}