fn wait_to_initiate_returns_early_with_connected_peer() {
        let (mut exec, id, peers, inspect, proxy, mut prof_stream, controller_pool) =
            setup_connected_peer_test();
        // Initialize context to a fixed point in time.
        exec.set_fake_time(fasync::Time::from_nanos(1000000000));

        let control_handle = prof_stream.control_handle();
        let mut evt_stream = proxy.take_event_stream();
        let evt_fut = evt_stream.next();
        pin_mut!(evt_fut);

        match exec.run_until_stalled(&mut evt_fut) {
            Poll::Pending => {}
            Poll::Ready(x) => {
                panic!("Expected a Pending response but got: {:?}", x);
            }
        };

        // Send an OnServiceFound event and get the event.
        send_on_service_found(id, control_handle.clone());
        let evt = match exec.run_until_stalled(&mut evt_fut) {
            Poll::Ready(Some(Ok(evt))) => evt,
            x => {
                panic!("Expected a Ready response but got: {:?}", x);
            }
        };

        // Propagate the event to the handler.
        let res = handle_profile_event(
            evt,
            proxy.clone(),
            peers.clone(),
            &inspect,
            controller_pool.clone(),
        );
        run_to_stalled(&mut exec);
        assert_eq!(Ok(()), res.map_err(|e| format!("{:?}", e)));

        // At this point, a remote peer was found, but hasn't connected yet. There
        // should be no entry for it.
        assert!(!peers.lock().is_connected(&id));

        // Fast forward time by .5 seconds. The threshold is 1 second, so the timer
        // to initiate connections has not been triggered.
        exec.set_fake_time(fasync::Time::from_nanos(1500000000));
        exec.wake_expired_timers();
        run_to_stalled(&mut exec);

        // A peer connects before the timeout.
        let _remote = send_on_connected(id, control_handle.clone());
        let evt = match exec.run_until_stalled(&mut evt_fut) {
            Poll::Ready(Some(Ok(evt))) => evt,
            x => {
                panic!("Expected a Ready response but got: {:?}", x);
            }
        };

        // Propagate the event to the handler.
        let res = handle_profile_event(evt, proxy, peers.clone(), &inspect, controller_pool);
        run_to_stalled(&mut exec);
        assert_eq!(Ok(()), res.map_err(|e| format!("{:?}", e)));

        // The remote peer connected to us, and should be in the map.
        assert!(peers.lock().is_connected(&id));

        // Fast forward time by 4.5 seconds. Ensure no outbound connection is initiated
        // by us, since the remote peer has assumed the INT role.
        exec.set_fake_time(fasync::Time::from_nanos(6000000000));
        exec.wake_expired_timers();
        run_to_stalled(&mut exec);

        let request = exec.run_until_stalled(&mut prof_stream.next());
        match request {
            Poll::Ready(x) => panic!("There should be no l2cap connection requests: {:?}", x),
            Poll::Pending => {}
        };
        run_to_stalled(&mut exec);
    }
/// Tests that A2DP sink does not assume the initiator role when a peer connects
/// before `INITIATOR_DELAY` timeout completes.
Tests that A2DP sink does not assume the initiator role when a peer connects
before `INITIATOR_DELAY` timeout completes.
Tests that A2DP sink does not assume the initiator role when a peer connects before ` INITIATOR_DELAY ` timeout completes .
fn wait_to_initiate_returns_early_with_connected_peer() {
        let (mut exec, id, peers, inspect, proxy, mut prof_stream, controller_pool) =
            setup_connected_peer_test();
        // Initialize context to a fixed point in time.
        exec.set_fake_time(fasync::Time::from_nanos(1000000000));
        let control_handle = prof_stream.control_handle();
        let mut evt_stream = proxy.take_event_stream();
        let evt_fut = evt_stream.next();
        pin_mut!(evt_fut);
        match exec.run_until_stalled(&mut evt_fut) {
            Poll::Pending => {}
            Poll::Ready(x) => {
                panic!("Expected a Pending response but got: {:?}", x);
            }
        };
        // Send an OnServiceFound event and get the event.
        send_on_service_found(id, control_handle.clone());
        let evt = match exec.run_until_stalled(&mut evt_fut) {
            Poll::Ready(Some(Ok(evt))) => evt,
            x => {
                panic!("Expected a Ready response but got: {:?}", x);
            }
        };
        // Propagate the event to the handler.
        let res = handle_profile_event(
            evt,
            proxy.clone(),
            peers.clone(),
            &inspect,
            controller_pool.clone(),
        );
        run_to_stalled(&mut exec);
        assert_eq!(Ok(()), res.map_err(|e| format!("{:?}", e)));
        // At this point, a remote peer was found, but hasn't connected yet. There
        // should be no entry for it.
        assert!(!peers.lock().is_connected(&id));
        // Fast forward time by .5 seconds. The threshold is 1 second, so the timer
        // to initiate connections has not been triggered.
        exec.set_fake_time(fasync::Time::from_nanos(1500000000));
        exec.wake_expired_timers();
        run_to_stalled(&mut exec);
        // A peer connects before the timeout.
        let _remote = send_on_connected(id, control_handle.clone());
        let evt = match exec.run_until_stalled(&mut evt_fut) {
            Poll::Ready(Some(Ok(evt))) => evt,
            x => {
                panic!("Expected a Ready response but got: {:?}", x);
            }
        };
        // Propagate the event to the handler.
        let res = handle_profile_event(evt, proxy, peers.clone(), &inspect, controller_pool);
        run_to_stalled(&mut exec);
        assert_eq!(Ok(()), res.map_err(|e| format!("{:?}", e)));
        // The remote peer connected to us, and should be in the map.
        assert!(peers.lock().is_connected(&id));
        // Fast forward time by 4.5 seconds. Ensure no outbound connection is initiated
        // by us, since the remote peer has assumed the INT role.
        exec.set_fake_time(fasync::Time::from_nanos(6000000000));
        exec.wake_expired_timers();
        run_to_stalled(&mut exec);
        let request = exec.run_until_stalled(&mut prof_stream.next());
        match request {
            Poll::Ready(x) => panic!("There should be no l2cap connection requests: {:?}", x),
            Poll::Pending => {}
        };
        run_to_stalled(&mut exec);
    }
fn wait_to_initiate_returns_early_with_connected_peer ( ) { let ( mut exec , id , peers , inspect , proxy , mut prof_stream , controller_pool ) = setup_connected_peer_test ( ) ; // Initialize context to a fixed point in time. exec . set_fake_time ( fasync :: Time :: from_nanos ( 1000000000 ) ) ; let control_handle = prof_stream . control_handle ( ) ; let mut evt_stream = proxy . take_event_stream ( ) ; let evt_fut = evt_stream . next ( ) ; pin_mut ! ( evt_fut ) ; match exec . run_until_stalled ( & mut evt_fut ) { Poll :: Pending => { } Poll :: Ready ( x ) => { panic ! ( " " x ) ; } } ; // Send an OnServiceFound event and get the event. send_on_service_found ( id , control_handle . clone ( ) ) ; let evt = match exec . run_until_stalled ( & mut evt_fut ) { Poll :: Ready ( Some ( Ok ( evt ) ) ) => evt , x => { panic ! ( " " x ) ; } } ; // Propagate the event to the handler. let res = handle_profile_event ( evt , proxy . clone ( ) , peers . clone ( ) , & inspect , controller_pool . clone ( ) , ) ; run_to_stalled ( & mut exec ) ; assert_eq ! ( Ok ( ( ) ) res map_err ( e format ( " " e ) ) ) ; // At this point, a remote peer was found, but hasn't connected yet. There // should be no entry for it. assert ! ( peers lock ( ) is_connected ( id ) ) ; // Fast forward time by .5 seconds. The threshold is 1 second, so the timer // to initiate connections has not been triggered. exec . set_fake_time ( fasync :: Time :: from_nanos ( 1500000000 ) ) ; exec . wake_expired_timers ( ) ; run_to_stalled ( & mut exec ) ; // A peer connects before the timeout. let _remote = send_on_connected ( id , control_handle . clone ( ) ) ; let evt = match exec . run_until_stalled ( & mut evt_fut ) { Poll :: Ready ( Some ( Ok ( evt ) ) ) => evt , x => { panic ! ( " " x ) ; } } ; // Propagate the event to the handler. let res = handle_profile_event ( evt , proxy , peers . clone ( ) , & inspect , controller_pool ) ; run_to_stalled ( & mut exec ) ; assert_eq ! ( Ok ( ( ) ) res map_err ( e format ( " " e ) ) ) ; // The remote peer connected to us, and should be in the map. assert ! ( peers lock ( ) is_connected ( id ) ) ; // Fast forward time by 4.5 seconds. Ensure no outbound connection is initiated // by us, since the remote peer has assumed the INT role. exec . set_fake_time ( fasync :: Time :: from_nanos ( 6000000000 ) ) ; exec . wake_expired_timers ( ) ; run_to_stalled ( & mut exec ) ; let request = exec . run_until_stalled ( & mut prof_stream . next ( ) ) ; match request { Poll :: Ready ( x ) => panic ! ( " " x ) , Poll :: Pending => { } } ; run_to_stalled ( & mut exec ) ; }
Tests that A2DP sink does not assume the initiator role when a peer connects
before `INITIATOR_DELAY` timeout completes.
Tests that A2DP sink does not assume the initiator role when a peer connects before ` INITIATOR_DELAY ` timeout completes .