1
- use std:: {
2
- sync:: { Arc , Mutex } ,
3
- time:: Duration ,
4
- } ;
1
+ use std:: { sync:: Arc , time:: Duration } ;
5
2
6
3
use assert_matches2:: { assert_let, assert_matches} ;
7
4
use futures_util:: FutureExt as _;
@@ -16,7 +13,7 @@ use ruma::{
16
13
room_id, EventId ,
17
14
} ;
18
15
use serde_json:: json;
19
- use tokio:: time:: timeout;
16
+ use tokio:: { sync :: Mutex , time:: timeout} ;
20
17
use wiremock:: {
21
18
matchers:: { header, method, path_regex} ,
22
19
Mock , Request , ResponseTemplate ,
@@ -152,7 +149,7 @@ async fn test_smoke() {
152
149
let event_id = event_id ! ( "$1" ) ;
153
150
154
151
let lock = Arc :: new ( Mutex :: new ( ( ) ) ) ;
155
- let lock_guard = lock. lock ( ) . unwrap ( ) ;
152
+ let lock_guard = lock. lock ( ) . await ;
156
153
157
154
let mock_lock = lock. clone ( ) ;
158
155
@@ -162,8 +159,15 @@ async fn test_smoke() {
162
159
. and ( path_regex ( r"^/_matrix/client/r0/rooms/.*/send/.*" ) )
163
160
. and ( header ( "authorization" , "Bearer 1234" ) )
164
161
. respond_with ( move |_req : & Request | {
165
- // Wait for the signal.
166
- drop ( mock_lock. lock ( ) . unwrap ( ) ) ;
162
+ // Wait for the signal from the main thread that we can process this query.
163
+ let mock_lock = mock_lock. clone ( ) ;
164
+ std:: thread:: spawn ( move || {
165
+ tokio:: runtime:: Runtime :: new ( ) . unwrap ( ) . block_on ( async {
166
+ drop ( mock_lock. lock ( ) . await ) ;
167
+ } ) ;
168
+ } )
169
+ . join ( )
170
+ . unwrap ( ) ;
167
171
168
172
ResponseTemplate :: new ( 200 ) . set_body_json ( json ! ( {
169
173
"event_id" : "$1" ,
@@ -236,7 +240,7 @@ async fn test_error() {
236
240
assert ! ( watch. is_empty( ) ) ;
237
241
238
242
let lock = Arc :: new ( Mutex :: new ( ( ) ) ) ;
239
- let lock_guard = lock. lock ( ) . unwrap ( ) ;
243
+ let lock_guard = lock. lock ( ) . await ;
240
244
241
245
let mock_lock = lock. clone ( ) ;
242
246
@@ -246,8 +250,15 @@ async fn test_error() {
246
250
. and ( path_regex ( r"^/_matrix/client/r0/rooms/.*/send/.*" ) )
247
251
. and ( header ( "authorization" , "Bearer 1234" ) )
248
252
. respond_with ( move |_req : & Request | {
249
- // Wait for the signal.
250
- drop ( mock_lock. lock ( ) . unwrap ( ) ) ;
253
+ // Wait for the signal from the main thread that we can process this query.
254
+ let mock_lock = mock_lock. clone ( ) ;
255
+ std:: thread:: spawn ( move || {
256
+ tokio:: runtime:: Runtime :: new ( ) . unwrap ( ) . block_on ( async {
257
+ drop ( mock_lock. lock ( ) . await ) ;
258
+ } ) ;
259
+ } )
260
+ . join ( )
261
+ . unwrap ( ) ;
251
262
252
263
ResponseTemplate :: new ( 500 )
253
264
} )
@@ -394,7 +405,7 @@ async fn test_reenabling_queue() {
394
405
395
406
mock_encryption_state ( & server, false ) . await ;
396
407
397
- let num_request = Mutex :: new ( 1 ) ;
408
+ let num_request = std :: sync :: Mutex :: new ( 1 ) ;
398
409
Mock :: given ( method ( "PUT" ) )
399
410
. and ( path_regex ( r"^/_matrix/client/r0/rooms/.*/send/.*" ) )
400
411
. and ( header ( "authorization" , "Bearer 1234" ) )
@@ -455,19 +466,26 @@ async fn test_cancellation() {
455
466
assert ! ( watch. is_empty( ) ) ;
456
467
457
468
let lock = Arc :: new ( Mutex :: new ( ( ) ) ) ;
458
- let lock_guard = lock. lock ( ) . unwrap ( ) ;
469
+ let lock_guard = lock. lock ( ) . await ;
459
470
460
471
let mock_lock = lock. clone ( ) ;
461
472
462
473
mock_encryption_state ( & server, false ) . await ;
463
474
464
- let num_request = Mutex :: new ( 1 ) ;
475
+ let num_request = std :: sync :: Mutex :: new ( 1 ) ;
465
476
Mock :: given ( method ( "PUT" ) )
466
477
. and ( path_regex ( r"^/_matrix/client/r0/rooms/.*/send/.*" ) )
467
478
. and ( header ( "authorization" , "Bearer 1234" ) )
468
479
. respond_with ( move |_req : & Request | {
469
- // Wait for the signal.
470
- drop ( mock_lock. lock ( ) . unwrap ( ) ) ;
480
+ // Wait for the signal from the main thread that we can process this query.
481
+ let mock_lock = mock_lock. clone ( ) ;
482
+ std:: thread:: spawn ( move || {
483
+ tokio:: runtime:: Runtime :: new ( ) . unwrap ( ) . block_on ( async {
484
+ drop ( mock_lock. lock ( ) . await ) ;
485
+ } ) ;
486
+ } )
487
+ . join ( )
488
+ . unwrap ( ) ;
471
489
472
490
let mut num_request = num_request. lock ( ) . unwrap ( ) ;
473
491
0 commit comments