@@ -58,13 +58,16 @@ pub struct PeerPair {
5858 pub peer_b_pub : TransportPublicKey ,
5959 pub peer_b : OutboundConnectionHandler < MockSocket > ,
6060 pub peer_b_addr : SocketAddr ,
61+ /// Keep channels alive - dropping this closes MockSocket inbound channels
62+ #[ allow( dead_code) ]
63+ channels : Channels ,
6164}
6265
6366/// Connected peer pair ready for data transfer
6467///
65- /// Encapsulates both connections and their peer handlers. The peer handlers
66- /// MUST be kept alive - dropping them closes the `inbound_packet_sender`
67- /// channel which causes `ConnectionClosed` errors.
68+ /// Encapsulates both connections and their peer handlers. The channels map
69+ /// MUST be kept alive - dropping it closes the MockSocket inbound channels
70+ /// which causes the listener tasks to exit and `ConnectionClosed` errors.
6871///
6972/// ## Example
7073///
@@ -76,12 +79,15 @@ pub struct PeerPair {
7679pub struct ConnectedPeerPair {
7780 pub conn_a : PeerConnection < MockSocket > ,
7881 pub conn_b : PeerConnection < MockSocket > ,
79- /// Must keep peer_a alive - it holds the inbound_packet_sender channel
82+ /// Must keep peer_a alive for send_queue channel
8083 #[ allow( dead_code) ]
8184 peer_a : OutboundConnectionHandler < MockSocket > ,
82- /// Must keep peer_b alive - it holds the inbound_packet_sender channel
85+ /// Must keep peer_b alive for send_queue channel
8386 #[ allow( dead_code) ]
8487 peer_b : OutboundConnectionHandler < MockSocket > ,
88+ /// Keep channels alive - dropping this closes MockSocket inbound channels
89+ #[ allow( dead_code) ]
90+ channels : Channels ,
8591}
8692
8793impl PeerPair {
@@ -102,6 +108,7 @@ impl PeerPair {
102108 conn_b,
103109 peer_a : self . peer_a ,
104110 peer_b : self . peer_b ,
111+ channels : self . channels ,
105112 }
106113 }
107114}
@@ -112,18 +119,32 @@ impl ConnectedPeerPair {
112119 /// Performs `iterations` send/receive cycles to allow LEDBAT congestion
113120 /// control to reach steady state before measurements begin.
114121 ///
122+ /// Returns the number of successful warmup iterations. If warmup fails
123+ /// early, benchmarks can still proceed (the connection may be less stable).
124+ ///
115125 /// ## Example
116126 ///
117127 /// ```rust,ignore
118128 /// let mut peers = create_connected_peers().await;
119- /// peers.warmup(5, 65536).await; // 5 x 64KB warmup transfers
129+ /// let completed = peers.warmup(5, 65536).await; // 5 x 64KB warmup transfers
120130 /// ```
121- pub async fn warmup ( & mut self , iterations : usize , message_size : usize ) {
122- for _ in 0 ..iterations {
131+ pub async fn warmup ( & mut self , iterations : usize , message_size : usize ) -> usize {
132+ let mut completed = 0 ;
133+ for i in 0 ..iterations {
123134 let msg = vec ! [ 0xABu8 ; message_size] ;
124- self . conn_a . send ( msg) . await . expect ( "warmup send" ) ;
125- let _: Vec < u8 > = self . conn_b . recv ( ) . await . expect ( "warmup recv" ) ;
135+ if let Err ( e) = self . conn_a . send ( msg) . await {
136+ eprintln ! ( "Warmup send {} failed: {:?}" , i, e) ;
137+ break ;
138+ }
139+ match self . conn_b . recv ( ) . await {
140+ Ok ( _) => completed += 1 ,
141+ Err ( e) => {
142+ eprintln ! ( "Warmup recv {} failed: {:?}" , i, e) ;
143+ break ;
144+ }
145+ }
126146 }
147+ completed
127148 }
128149
129150 /// Get mutable references to both connections
@@ -147,7 +168,7 @@ pub async fn create_peer_pair(channels: Channels) -> PeerPair {
147168 . expect ( "create peer A" ) ;
148169
149170 let ( peer_b_pub, peer_b, peer_b_addr) =
150- create_mock_peer ( PacketDropPolicy :: ReceiveAll , channels)
171+ create_mock_peer ( PacketDropPolicy :: ReceiveAll , channels. clone ( ) )
151172 . await
152173 . expect ( "create peer B" ) ;
153174
@@ -158,6 +179,7 @@ pub async fn create_peer_pair(channels: Channels) -> PeerPair {
158179 peer_b_pub,
159180 peer_b,
160181 peer_b_addr,
182+ channels,
161183 }
162184}
163185
@@ -174,7 +196,7 @@ pub async fn create_peer_pair_with_delay(channels: Channels, delay: Duration) ->
174196 let ( peer_b_pub, peer_b, peer_b_addr) = create_mock_peer_with_delay (
175197 PacketDropPolicy :: ReceiveAll ,
176198 PacketDelayPolicy :: Fixed ( delay) ,
177- channels,
199+ channels. clone ( ) ,
178200 )
179201 . await
180202 . expect ( "create peer B" ) ;
@@ -186,6 +208,7 @@ pub async fn create_peer_pair_with_delay(channels: Channels, delay: Duration) ->
186208 peer_b_pub,
187209 peer_b,
188210 peer_b_addr,
211+ channels,
189212 }
190213}
191214
0 commit comments