Skip to content

Commit 148168c

Browse files
committedJul 10, 2024·
Add not-smart Server::new_async method to custom mockito implementation
1 parent b347187 commit 148168c

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed
 

‎app/src/deps/mockito/server.rs

+20-14
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,33 @@
11
use http_body_util::Full;
2-
use hyper::body::Bytes;
3-
use hyper::body::Incoming;
4-
use hyper::server::conn::http1::Builder;
5-
use hyper::service::service_fn;
6-
use hyper::{Request, Response as HyperResponse};
2+
use hyper::{
3+
body::{Bytes, Incoming},
4+
server::conn::http1::Builder,
5+
service::service_fn,
6+
Request, Response as HyperResponse,
7+
};
78
use hyper_util::rt::TokioIo;
8-
use std::net::SocketAddr;
9-
use std::sync::{Arc, RwLock};
10-
use std::thread;
11-
use tokio::net::TcpListener;
12-
use tokio::runtime;
13-
use tokio::task::spawn;
9+
use std::{
10+
future::Future,
11+
net::SocketAddr,
12+
sync::{Arc, RwLock},
13+
thread,
14+
};
15+
use tokio::{net::TcpListener, runtime, task::spawn};
1416

15-
use super::error::MockError;
16-
use super::mock::Mock;
17-
use super::state::State;
17+
use super::{error::MockError, mock::Mock, state::State};
1818

1919
pub struct Server {
2020
address: SocketAddr,
2121
state: Arc<RwLock<State>>,
2222
}
2323

2424
impl Server {
25+
/// Beginning in mockito 1.3.1, calling [`Server::new`] was no longer permitted from inside a
26+
/// tokio runtime. We use a fake-async server here just to satisfy the interface.
27+
pub async fn new_async() -> Server {
28+
Self::new()
29+
}
30+
2531
pub fn new() -> Server {
2632
let address = SocketAddr::from(([127, 0, 0, 1], 5001));
2733
let state = Arc::new(RwLock::new(State::new()));

0 commit comments

Comments
 (0)
Please sign in to comment.