/// Tests an application based on Carnelian. The `assistant` parameter will
/// be used to create a single new view for testing. The test will run until the
/// first update call, or until a five second timeout. The Result returned is the
/// result of the test, an Ok(()) result means the test passed.
Tests an application based on Carnelian. The `assistant` parameter will
be used to create a single new view for testing. The test will run until the
first update call, or until a five second timeout. The Result returned is the
result of the test, an Ok(()) result means the test passed.
Tests an application based on Carnelian . The ` assistant ` parameter will be used to create a single new view for testing . The test will run until the first update call or until a five second timeout . The Result returned is the result of the test an Ok (( )) result means the test passed .
pub fn test(assistant_creator_func: AssistantCreatorFunc) -> Result<(), Error> {
        let config = Self::load_config().context("loading config failed in test")?;
        let mut executor = fasync::LocalExecutor::new().context("Error creating executor")?;
        let (internal_sender, mut internal_receiver) = unbounded::<MessageInternal>();
        let f = async {
            let app_context = AppContext { sender: internal_sender.clone() };
            let assistant_creator = assistant_creator_func(&app_context);
            let assistant = assistant_creator.await?;
            let strat =
                create_app_strategy(&assistant, &config, FIRST_VIEW_KEY, &internal_sender).await?;
            strat.create_view_for_testing(&internal_sender)?;
            let mut app = App::new(internal_sender, strat, assistant);
            let mut frame_count = 0;
            app.app_init_common().await?;
            loop {
                let timeout = Timer::new(500_i64.millis().after_now());
                let either = futures::future::select(timeout, internal_receiver.next());
                let resolved = either.await;
                match resolved {
                    Either::Left(_) => {
                        return Err(format_err!(
                            "Carnelian test got timeout before seeing 10 frames"
                        ));
                    }
                    Either::Right((right_result, _)) => {
                        let message = right_result.expect("message");
                        match message {
                            MessageInternal::Render(_) => {
                                frame_count += 1;
                            }
                            MessageInternal::RenderAllViews => {
                                frame_count += 1;
                            }
                            _ => (),
                        }
                        app.handle_message(message).await.expect("handle_message failed");
                        if frame_count > 10 {
                            break;
                        }
                    }
                }
            }
            Ok::<(), Error>(())
        };
        executor.run_singlethreaded(f)?;
        Ok(())
    }
pub fn test ( assistant_creator_func : AssistantCreatorFunc ) -> Result < ( ) , Error > { let config = Self :: load_config ( ) . context ( " " ) ? ; let mut executor = fasync :: LocalExecutor :: new ( ) . context ( " " ) ? ; let ( internal_sender , mut internal_receiver ) = unbounded :: < MessageInternal > ( ) ; let f = async { let app_context = AppContext { sender : internal_sender . clone ( ) } ; let assistant_creator = assistant_creator_func ( & app_context ) ; let assistant = assistant_creator . await ? ; let strat = create_app_strategy ( & assistant , & config , FIRST_VIEW_KEY , & internal_sender ) . await ? ; strat . create_view_for_testing ( & internal_sender ) ? ; let mut app = App :: new ( internal_sender , strat , assistant ) ; let mut frame_count = 0 ; app . app_init_common ( ) . await ? ; loop { let timeout = Timer :: new ( 500_i64 . millis ( ) . after_now ( ) ) ; let either = futures :: future :: select ( timeout , internal_receiver . next ( ) ) ; let resolved = either . await ; match resolved { Either :: Left ( _ ) => { return Err ( format_err ! ( " " ) ) ; } Either :: Right ( ( right_result , _ ) ) => { let message = right_result . expect ( " " ) ; match message { MessageInternal :: Render ( _ ) => { frame_count += 1 ; } MessageInternal :: RenderAllViews => { frame_count += 1 ; } _ => ( ) , } app . handle_message ( message ) . await . expect ( " " ) ; if frame_count > 10 { break ; } } } } Ok :: < ( ) , Error > ( ( ) ) } ; executor . run_singlethreaded ( f ) ? ; Ok ( ( ) ) }
Tests an application based on Carnelian.
Tests an application based on Carnelian .
assistant_creator_func
AssistantCreatorFunc