@@ -26,18 +26,13 @@ async fn test_twcc_receiver_interceptor_before_any_packets() -> Result<()> {
26
26
)
27
27
. await ;
28
28
29
- let pkts = stream. written_rtcp ( ) . await . unwrap ( ) ;
30
- assert_eq ! ( pkts. len( ) , 1 ) ;
31
- if let Some ( tlcc) = pkts[ 0 ] . as_any ( ) . downcast_ref :: < TransportLayerCc > ( ) {
32
- assert_eq ! ( 0 , tlcc. packet_status_count) ;
33
- assert_eq ! ( 0 , tlcc. fb_pkt_count) ;
34
- assert_eq ! ( 0 , tlcc. base_sequence_number) ;
35
- assert_eq ! ( 0 , tlcc. media_ssrc) ;
36
- assert_eq ! ( 0 , tlcc. reference_time) ;
37
- assert_eq ! ( 0 , tlcc. recv_deltas. len( ) ) ;
38
- assert_eq ! ( 0 , tlcc. packet_chunks. len( ) ) ;
39
- } else {
40
- assert ! ( false ) ;
29
+ tokio:: select! {
30
+ pkts = stream. written_rtcp( ) => {
31
+ assert!( pkts. map( |p| p. is_empty( ) ) . unwrap_or( true ) , "Should not have sent an RTCP packet before receiving the first RTP packets" )
32
+ }
33
+ _ = tokio:: time:: sleep( Duration :: from_millis( 300 ) ) => {
34
+ // All good
35
+ }
41
36
}
42
37
43
38
stream. close ( ) . await ?;
@@ -101,9 +96,7 @@ async fn test_twcc_receiver_interceptor_after_rtp_packets() -> Result<()> {
101
96
Ok ( ( ) )
102
97
}
103
98
104
- //TODO: remove this conditional test
105
- #[ cfg( not( any( target_os = "macos" , target_os = "windows" ) ) ) ]
106
- #[ tokio:: test]
99
+ #[ tokio:: test( start_paused = true ) ]
107
100
async fn test_twcc_receiver_interceptor_different_delays_between_rtp_packets ( ) -> Result < ( ) > {
108
101
let builder = Receiver :: builder ( ) . with_interval ( Duration :: from_millis ( 500 ) ) ;
109
102
let icpr = builder. build ( "" ) ?;
@@ -124,7 +117,7 @@ async fn test_twcc_receiver_interceptor_different_delays_between_rtp_packets() -
124
117
125
118
let delays = vec ! [ 0 , 10 , 100 , 200 ] ;
126
119
for ( i, d) in delays. iter ( ) . enumerate ( ) {
127
- tokio:: time:: sleep ( Duration :: from_millis ( * d) ) . await ;
120
+ tokio:: time:: advance ( Duration :: from_millis ( * d) ) . await ;
128
121
129
122
let mut hdr = rtp:: header:: Header :: default ( ) ;
130
123
let tcc = TransportCcExtension {
@@ -139,13 +132,17 @@ async fn test_twcc_receiver_interceptor_different_delays_between_rtp_packets() -
139
132
..Default :: default ( )
140
133
} )
141
134
. await ;
135
+
136
+ // Yield so this packet can be processed
137
+ tokio:: task:: yield_now ( ) . await ;
142
138
}
143
139
144
- // tick immediately, let's ignore the first rtcp pkt
145
- let _ = stream. written_rtcp ( ) . await . unwrap ( ) ;
140
+ // Force a packet to be generated
141
+ tokio:: time:: advance ( Duration :: from_millis ( 2001 ) ) . await ;
142
+ tokio:: task:: yield_now ( ) . await ;
146
143
147
- // the second 500ms tick will works
148
144
let pkts = stream. written_rtcp ( ) . await . unwrap ( ) ;
145
+
149
146
assert_eq ! ( pkts. len( ) , 1 ) ;
150
147
if let Some ( cc) = pkts[ 0 ] . as_any ( ) . downcast_ref :: < TransportLayerCc > ( ) {
151
148
assert_eq ! ( 0 , cc. base_sequence_number) ;
@@ -171,9 +168,7 @@ async fn test_twcc_receiver_interceptor_different_delays_between_rtp_packets() -
171
168
Ok ( ( ) )
172
169
}
173
170
174
- //TODO: remove this conditional test
175
- #[ cfg( not( target_os = "macos" ) ) ]
176
- #[ tokio:: test]
171
+ #[ tokio:: test( start_paused = true ) ]
177
172
async fn test_twcc_receiver_interceptor_packet_loss ( ) -> Result < ( ) > {
178
173
let builder = Receiver :: builder ( ) . with_interval ( Duration :: from_secs ( 2 ) ) ;
179
174
let icpr = builder. build ( "" ) ?;
@@ -192,26 +187,21 @@ async fn test_twcc_receiver_interceptor_packet_loss() -> Result<()> {
192
187
)
193
188
. await ;
194
189
195
- let sequence_number_to_delay: HashMap < u16 , u64 > = [
190
+ let sequence_number_to_delay = & [
196
191
( 0 , 0 ) ,
197
192
( 1 , 10 ) ,
198
193
( 4 , 100 ) ,
199
194
( 8 , 200 ) ,
200
195
( 9 , 20 ) ,
201
196
( 10 , 20 ) ,
202
197
( 30 , 300 ) ,
203
- ]
204
- . iter ( )
205
- . cloned ( )
206
- . collect ( ) ;
207
-
208
- for i in & [ 0 , 1 , 4 , 8 , 9 , 10 , 30 ] {
209
- let d = sequence_number_to_delay. get ( i) . unwrap ( ) ;
210
- tokio:: time:: sleep ( Duration :: from_millis ( * d) ) . await ;
198
+ ] ;
211
199
200
+ for ( i, d) in sequence_number_to_delay {
201
+ tokio:: time:: advance ( Duration :: from_millis ( * d) ) . await ;
212
202
let mut hdr = rtp:: header:: Header :: default ( ) ;
213
203
let tcc = TransportCcExtension {
214
- transport_sequence : * i as u16 ,
204
+ transport_sequence : * i,
215
205
}
216
206
. marshal ( ) ?;
217
207
hdr. set_extension ( 1 , tcc) ?;
@@ -221,13 +211,17 @@ async fn test_twcc_receiver_interceptor_packet_loss() -> Result<()> {
221
211
..Default :: default ( )
222
212
} )
223
213
. await ;
214
+
215
+ // Yield so this packet can be processed
216
+ tokio:: task:: yield_now ( ) . await ;
224
217
}
225
218
226
- // tick immediately, let's ignore the first rtcp pkt
227
- let _ = stream. written_rtcp ( ) . await . unwrap ( ) ;
219
+ // Force a packet to be generated
220
+ tokio:: time:: advance ( Duration :: from_millis ( 2001 ) ) . await ;
221
+ tokio:: task:: yield_now ( ) . await ;
228
222
229
- // the second 500ms tick will works
230
223
let pkts = stream. written_rtcp ( ) . await . unwrap ( ) ;
224
+
231
225
assert_eq ! ( pkts. len( ) , 1 ) ;
232
226
if let Some ( cc) = pkts[ 0 ] . as_any ( ) . downcast_ref :: < TransportLayerCc > ( ) {
233
227
assert_eq ! ( 0 , cc. base_sequence_number) ;
0 commit comments