|
| 1 | +// mockito::Server is behind a SYNC mutex so that only one test at the same time can access it |
| 2 | +// otherwise, as async tests are run on multiple threads, the mock response of one test might overwrite |
| 3 | +// the mock response of another, causing the test to fail |
| 4 | +// acquiring the mutex and the beginning of each test and dropping the guard only at the end, |
| 5 | +// ensures that only one test at the time can set the mock response |
| 6 | +// this enables running the tests without specifying each time "-- --test-threads=1" |
| 7 | +#[allow(clippy::await_holding_lock)] |
1 | 8 | #[cfg(test)] |
2 | 9 | mod test { |
3 | 10 | use candid::Principal; |
@@ -86,14 +93,12 @@ mod test { |
86 | 93 | } |
87 | 94 |
|
88 | 95 | lazy_static! { |
89 | | - // mockito::Server is behind a SYNC mutex so that only one test at the same time can access it |
90 | | - // otherwise, as async tests are run on multiple threads, the mock response of one test might overwrite |
91 | | - // the mock response of another, causing the test to fail |
92 | | - // acquiring the mutex and the beginning of each test and dropping the guard only at the end, |
93 | | - // ensures that only one test at the time can set the mock response |
94 | | - // this enables running the tests without specifying each time "-- --test-threads=1" |
95 | | - static ref MOCK_SERVER: Arc<Mutex<mockito::Server>> = |
96 | | - Arc::new(Mutex::new(mockito::Server::new_with_opts(mockito::ServerOpts { port: 51558, ..Default::default() }))); |
| 96 | + static ref MOCK_SERVER: Arc<Mutex<mockito::Server>> = Arc::new(Mutex::new( |
| 97 | + mockito::Server::new_with_opts(mockito::ServerOpts { |
| 98 | + port: 51558, |
| 99 | + ..Default::default() |
| 100 | + }) |
| 101 | + )); |
97 | 102 | } |
98 | 103 |
|
99 | 104 | fn create_poller( |
@@ -332,7 +337,7 @@ mod test { |
332 | 337 | .mock("GET", path) |
333 | 338 | .with_chunked_body(|w| { |
334 | 339 | thread::sleep(Duration::from_millis(POLLING_TIMEOUT_MS + 10)); |
335 | | - w.write_all(&vec![]) |
| 340 | + w.write_all(&[]) |
336 | 341 | }) |
337 | 342 | .expect(2) |
338 | 343 | .create_async() |
|
0 commit comments