@@ -145,7 +145,7 @@ async fn test_send_attachment_from_file() {
145
145
}
146
146
147
147
// The media upload finishes.
148
- {
148
+ let ( final_index , final_progress ) = {
149
149
assert_let_timeout ! (
150
150
Duration :: from_secs( 3 ) ,
151
151
Some ( VectorDiff :: Set { index: 1 , value: item } ) = timeline_stream. next( )
@@ -164,7 +164,9 @@ async fn test_send_attachment_from_file() {
164
164
assert_let ! ( MessageType :: File ( file) = msg. msgtype( ) ) ;
165
165
assert_let ! ( MediaSource :: Plain ( uri) = & file. source) ;
166
166
assert ! ( uri. to_string( ) . contains( "localhost" ) ) ;
167
- }
167
+
168
+ ( * index, * progress)
169
+ } ;
168
170
169
171
// Eventually, the media is updated with the final MXC IDs…
170
172
{
@@ -173,7 +175,14 @@ async fn test_send_attachment_from_file() {
173
175
Some ( VectorDiff :: Set { index: 1 , value: item } ) = timeline_stream. next( )
174
176
) ;
175
177
assert_let ! ( Some ( msg) = item. content( ) . as_message( ) ) ;
176
- assert_matches ! ( item. send_state( ) , Some ( EventSendState :: NotSentYet { progress: None } ) ) ;
178
+ assert_let ! (
179
+ Some ( EventSendState :: NotSentYet {
180
+ progress: Some ( EventSendProgress :: MediaUpload { index, progress } )
181
+ } ) = item. send_state( )
182
+ ) ;
183
+ assert_eq ! ( * index, final_index) ;
184
+ assert_eq ! ( progress. current, final_progress. current) ;
185
+ assert_eq ! ( progress. total, final_progress. total) ;
177
186
assert_eq ! ( get_filename_and_caption( msg. msgtype( ) ) , ( "test.bin" , Some ( "caption" ) ) ) ;
178
187
179
188
// The URI now refers to the final MXC URI.
@@ -284,35 +293,31 @@ async fn test_send_attachment_from_bytes() {
284
293
285
294
assert_let ! ( Some ( EventSendState :: NotSentYet { progress } ) = item. send_state( ) ) ;
286
295
287
- match progress {
288
- Some ( EventSendProgress :: MediaUpload { index, progress } ) => {
289
- // We're only uploading a single file.
290
- assert_eq ! ( * index, 0 ) ;
291
-
292
- // The progress is reported in units of the unencrypted file size.
293
- assert ! ( progress. current <= progress. total) ;
294
- assert_eq ! ( progress. total, size) ;
295
-
296
- // The progress only increases.
297
- if let Some ( prev_progress) = prev_progress {
298
- assert ! ( progress. current >= prev_progress. current) ;
299
- }
300
- prev_progress = Some ( * progress) ;
301
-
302
- // The URI still refers to the local cache.
303
- assert_let ! ( MessageType :: File ( file) = msg. msgtype( ) ) ;
304
- assert_let ! ( MediaSource :: Plain ( uri) = & file. source) ;
305
- assert ! ( uri. to_string( ) . contains( "localhost" ) ) ;
306
- }
307
- None => {
308
- // The upload finished and the URI now refers to the final MXC URI.
309
- assert_let ! ( MessageType :: File ( file) = msg. msgtype( ) ) ;
310
- assert_let ! ( MediaSource :: Plain ( uri) = & file. source) ;
311
- assert_eq ! ( uri. to_string( ) , "mxc://sdk.rs/media" ) ;
312
-
313
- break ;
314
- }
296
+ assert_let ! ( Some ( EventSendProgress :: MediaUpload { index, progress } ) = progress) ;
297
+
298
+ // We're only uploading a single file.
299
+ assert_eq ! ( * index, 0 ) ;
300
+
301
+ // The progress is reported in units of the unencrypted file size.
302
+ assert ! ( progress. current <= progress. total) ;
303
+ assert_eq ! ( progress. total, size) ;
304
+
305
+ // The progress only increases.
306
+ if let Some ( prev_progress) = prev_progress {
307
+ assert ! ( progress. current >= prev_progress. current) ;
315
308
}
309
+ prev_progress = Some ( * progress) ;
310
+
311
+ assert_let ! ( MessageType :: File ( file) = msg. msgtype( ) ) ;
312
+ assert_let ! ( MediaSource :: Plain ( uri) = & file. source) ;
313
+
314
+ // Check if the upload finished and the URI now refers to the final MXC URI.
315
+ if progress. current == progress. total && * uri == "mxc://sdk.rs/media" {
316
+ break ;
317
+ }
318
+
319
+ // Otherwise, the URI still refers to the local cache.
320
+ assert ! ( uri. to_string( ) . contains( "localhost" ) ) ;
316
321
}
317
322
}
318
323
@@ -422,7 +427,7 @@ async fn test_send_gallery_from_bytes() {
422
427
}
423
428
424
429
// The media upload finishes.
425
- {
430
+ let ( final_index , final_progress ) = {
426
431
assert_let_timeout ! (
427
432
Duration :: from_secs( 3 ) ,
428
433
Some ( VectorDiff :: Set { index: 1 , value: item } ) = timeline_stream. next( )
@@ -453,7 +458,9 @@ async fn test_send_gallery_from_bytes() {
453
458
// The URI still refers to the local cache.
454
459
assert_let ! ( MediaSource :: Plain ( uri) = & file. source) ;
455
460
assert ! ( uri. to_string( ) . contains( "localhost" ) ) ;
456
- }
461
+
462
+ ( * index, progress. clone ( ) )
463
+ } ;
457
464
458
465
// Eventually, the media is updated with the final MXC IDs…
459
466
{
@@ -462,7 +469,14 @@ async fn test_send_gallery_from_bytes() {
462
469
Some ( VectorDiff :: Set { index: 1 , value: item } ) = timeline_stream. next( )
463
470
) ;
464
471
assert_let ! ( Some ( msg) = item. content( ) . as_message( ) ) ;
465
- assert_matches ! ( item. send_state( ) , Some ( EventSendState :: NotSentYet { progress: None } ) ) ;
472
+ assert_let ! (
473
+ Some ( EventSendState :: NotSentYet {
474
+ progress: Some ( EventSendProgress :: MediaUpload { index, progress } )
475
+ } ) = item. send_state( )
476
+ ) ;
477
+ assert_eq ! ( * index, final_index) ;
478
+ assert_eq ! ( progress. current, final_progress. current) ;
479
+ assert_eq ! ( progress. total, final_progress. total) ;
466
480
467
481
// Message is gallery of expected length
468
482
assert_let ! ( MessageType :: Gallery ( content) = msg. msgtype( ) ) ;
0 commit comments