// Helper function for bringing up an environment with a single handler for a
// single SettingType and validating the environment initialization result.
Helper function for bringing up an environment with a single handler for a
single SettingType and validating the environment initialization result.
Helper function for bringing up an environment with a single handler for a single SettingType and validating the environment initialization result .
async fn verify_restore_handling(
    response_generate: Box<dyn Fn() -> SettingResponseResult + Send + Sync + 'static>,
    success: bool,
) {
    let counter: Arc<Mutex<u64>> = Arc::new(Mutex::new(0));
    let counter_clone = counter.clone();
    if let Ok(environment) = EnvironmentBuilder::new(InMemoryStorageFactory::create())
        .handler(
            SettingType::Unknown,
            create_setting_handler(Box::new(move |command| {
                let counter = counter_clone.clone();
                if let Command::HandleRequest(SettingRequest::Restore, responder) = command {
                    let result = (response_generate)();
                    return Box::pin(async move {
                        let mut counter_lock = counter.lock().await;
                        *counter_lock += 1;
                        responder.send(result).ok();
                        return ();
                    });
                } else {
                    return Box::pin(async move {});
                }
            })),
        )
        .agents(&[Arc::new(Mutex::new(RestoreAgent::new()))])
        .settings(&[SettingType::Unknown])
        .spawn_nested(ENV_NAME)
        .await
    {
        if let Ok(result) = environment.completion_rx.await {
            assert!(result.is_ok(), success);
            assert_eq!(*counter.lock().await, 1);
        } else {
            panic!("Completion rx should have returned the environment initialization result");
        }
    } else {
        panic!("Should have successfully created environment");
    }
}
async fn verify_restore_handling ( response_generate : Box < dyn Fn ( ) -> SettingResponseResult + Send + Sync + ' static > , success : bool , ) { let counter : Arc < Mutex < u64 > > = Arc :: new ( Mutex :: new ( 0 ) ) ; let counter_clone = counter . clone ( ) ; if let Ok ( environment ) = EnvironmentBuilder :: new ( InMemoryStorageFactory :: create ( ) ) . handler ( SettingType :: Unknown , create_setting_handler ( Box :: new ( move | command | { let counter = counter_clone . clone ( ) ; if let Command :: HandleRequest ( SettingRequest :: Restore , responder ) = command { let result = ( response_generate ) ( ) ; return Box :: pin ( async move { let mut counter_lock = counter . lock ( ) . await ; * counter_lock += 1 ; responder . send ( result ) . ok ( ) ; return ( ) ; } ) ; } else { return Box :: pin ( async move { } ) ; } } ) ) , ) . agents ( & [ Arc :: new ( Mutex :: new ( RestoreAgent :: new ( ) ) ) ] ) . settings ( & [ SettingType :: Unknown ] ) . spawn_nested ( ENV_NAME ) . await { if let Ok ( result ) = environment . completion_rx . await { assert ! ( result is_ok ( ) success ) ; assert_eq ! ( counter lock ( ) await 1 ) ; } else { panic ! ( " " ) ; } } else { panic ! ( " " ) ; } }
Helper function for bringing up an environment with a single handler for a
single SettingType and validating the environment initialization result.
Helper function for bringing up an environment with a single handler for a single SettingType and validating the environment initialization result .
response_generate
Box<dyn Fn() -> SettingResponseResult + Send + Sync + 'static>
success
bool