fn wait_to_initiate_returns_early_with_connected_peer() {
        let (mut exec, peers, 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 peer_id = PeerId(1);

        // Simulate getting the service found event.
        let attributes = vec![Attribute {
            id: ATTR_BLUETOOTH_PROFILE_DESCRIPTOR_LIST,
            element: DataElement::Sequence(vec![Some(Box::new(DataElement::Sequence(vec![
                Some(Box::new(Uuid::from(ServiceClassProfileIdentifier::AudioSource).into())),
                Some(Box::new(DataElement::Uint16(0x0103))), // Version 1.3
            ])))]),
        }];
        handle_services_found(
            &peer_id,
            &attributes,
            peers.clone(),
            controller_pool.clone(),
            proxy.clone(),
        );

        // 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(&peer_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, transport) =
            zx::Socket::create(zx::SocketOpts::DATAGRAM).expect("socket creation fail");
        let channel = Channel { socket: Some(transport), ..Channel::new_empty() };
        handle_connection(&peer_id, channel, false, &mut peers.lock(), &mut controller_pool.lock());

        run_to_stalled(&mut exec);

        // The remote peer connected to us, and should be in the map.
        assert!(peers.lock().is_connected(&peer_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, peers, 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 peer_id = PeerId(1);
        // Simulate getting the service found event.
        let attributes = vec![Attribute {
            id: ATTR_BLUETOOTH_PROFILE_DESCRIPTOR_LIST,
            element: DataElement::Sequence(vec![Some(Box::new(DataElement::Sequence(vec![
                Some(Box::new(Uuid::from(ServiceClassProfileIdentifier::AudioSource).into())),
                Some(Box::new(DataElement::Uint16(0x0103))), // Version 1.3
            ])))]),
        }];
        handle_services_found(
            &peer_id,
            &attributes,
            peers.clone(),
            controller_pool.clone(),
            proxy.clone(),
        );
        // 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(&peer_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, transport) =
            zx::Socket::create(zx::SocketOpts::DATAGRAM).expect("socket creation fail");
        let channel = Channel { socket: Some(transport), ..Channel::new_empty() };
        handle_connection(&peer_id, channel, false, &mut peers.lock(), &mut controller_pool.lock());
        run_to_stalled(&mut exec);
        // The remote peer connected to us, and should be in the map.
        assert!(peers.lock().is_connected(&peer_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 , peers , 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 peer_id = PeerId ( 1 ) ; // Simulate getting the service found event. let attributes = vec ! [ Attribute { id ATTR_BLUETOOTH_PROFILE_DESCRIPTOR_LIST element DataElement Sequence ( vec [ Some ( Box new ( DataElement Sequence ( vec [ Some ( Box new ( Uuid from ( ServiceClassProfileIdentifier AudioSource ) into ( ) ) ) Some ( Box new ( DataElement Uint16 ( 0x0103 ) ) ) // Version 1.3 ] ) ) ) ] ) } ] ; handle_services_found ( & peer_id , & attributes , peers . clone ( ) , controller_pool . clone ( ) , proxy . clone ( ) , ) ; // 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 ( peer_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 , transport ) = zx :: Socket :: create ( zx :: SocketOpts :: DATAGRAM ) . expect ( " " ) ; let channel = Channel { socket : Some ( transport ) , .. Channel :: new_empty ( ) } ; handle_connection ( & peer_id , channel , false , & mut peers . lock ( ) , & mut controller_pool . lock ( ) ) ; run_to_stalled ( & mut exec ) ; // The remote peer connected to us, and should be in the map. assert ! ( peers lock ( ) is_connected ( peer_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 .