/// Test scenario where we tell the controller to stop the component and
/// the component stops immediately.
Test scenario where we tell the controller to stop the component and
the component stops immediately.
Test scenario where we tell the controller to stop the component and the component stops immediately .
async fn stop_component_well_behaved_component_stop() {
        // Create a mock controller which simulates immediately shutting down
        // the component.
        let stop_timeout = zx::Duration::from_millis(5);
        let kill_timeout = zx::Duration::from_millis(1);
        let (client, server) =
            endpoints::create_endpoints::<fcrunner::ComponentControllerMarker>().unwrap();
        let server_channel_koid = server
            .as_handle_ref()
            .basic_info()
            .expect("failed to get basic info on server channel")
            .koid;
        // Create a request map which the MockController will fill with
        // requests it received related to mocked component.
        let requests: Arc<Mutex<HashMap<Koid, Vec<ControlMessage>>>> =
            Arc::new(Mutex::new(HashMap::new()));
        let controller = MockController::new(server, requests.clone(), server_channel_koid);
        controller.serve();
        let stop_timer = Box::pin(fasync::Timer::new(fasync::Time::after(stop_timeout)));
        let kill_timer = Box::pin(async move {
            let timer = fasync::Timer::new(fasync::Time::after(kill_timeout));
            timer.await;
        });
        let client_proxy = client.into_proxy().expect("failed to convert client to proxy");
        let component = ComponentController::new(client_proxy);
        match stop_component_internal(&component, stop_timer, kill_timer).await {
            Ok(ComponentStopOutcome {
                request: StopRequestSuccess::Stopped,
                component_exit_status: zx::Status::OK,
            }) => {}
            Ok(result) => {
                panic!("unexpected successful stop result {:?}", result);
            }
            Err(e) => {
                panic!("unexpected error stopping component {:?}", e);
            }
        }
        let msg_map = requests.lock().await;
        let msg_list =
            msg_map.get(&server_channel_koid).expect("No messages received on the channel");
        // The controller should have only seen a STOP message since it stops
        // the component immediately.
        assert_eq!(msg_list, &vec![ControlMessage::Stop]);
    }
async fn stop_component_well_behaved_component_stop ( ) { // Create a mock controller which simulates immediately shutting down // the component. let stop_timeout = zx :: Duration :: from_millis ( 5 ) ; let kill_timeout = zx :: Duration :: from_millis ( 1 ) ; let ( client , server ) = endpoints :: create_endpoints :: < fcrunner :: ComponentControllerMarker > ( ) . unwrap ( ) ; let server_channel_koid = server . as_handle_ref ( ) . basic_info ( ) . expect ( " " ) . koid ; // Create a request map which the MockController will fill with // requests it received related to mocked component. let requests : Arc < Mutex < HashMap < Koid , Vec < ControlMessage > > > > = Arc :: new ( Mutex :: new ( HashMap :: new ( ) ) ) ; let controller = MockController :: new ( server , requests . clone ( ) , server_channel_koid ) ; controller . serve ( ) ; let stop_timer = Box :: pin ( fasync :: Timer :: new ( fasync :: Time :: after ( stop_timeout ) ) ) ; let kill_timer = Box :: pin ( async move { let timer = fasync :: Timer :: new ( fasync :: Time :: after ( kill_timeout ) ) ; timer . await ; } ) ; let client_proxy = client . into_proxy ( ) . expect ( " " ) ; let component = ComponentController :: new ( client_proxy ) ; match stop_component_internal ( & component , stop_timer , kill_timer ) . await { Ok ( ComponentStopOutcome { request : StopRequestSuccess :: Stopped , component_exit_status : zx :: Status :: OK , } ) => { } Ok ( result ) => { panic ! ( " " result ) ; } Err ( e ) => { panic ! ( " " e ) ; } } let msg_map = requests . lock ( ) . await ; let msg_list = msg_map . get ( & server_channel_koid ) . expect ( " " ) ; // The controller should have only seen a STOP message since it stops // the component immediately. assert_eq ! ( msg_list vec [ ControlMessage Stop ] ) ; }
Test scenario where we tell the controller to stop the component and
the component stops immediately.
Test scenario where we tell the controller to stop the component and the component stops immediately .