January 2019
Intermediate to advanced
520 pages
14h 32m
English
We will start a server instance in a separate thread, because Rust runs tests in multiple threads, and we won't create a server instance with a unique port for every test run to show how you can use a shared instance, because integration tests often need to reuse the same application instance. Create a shared flag that we will use to detect routers that have already started:
lazy_static! { static ref STARTED: Mutex<bool> = Mutex::new(false);}
Now, we will use this Mutex to create a function to start a server. Look at the following setup function implementation:
fn setup() { let mut started = STARTED.lock().unwrap(); if !*started { thread::spawn(|| { let url = mockito::server_url(); let _signup = add_mock("POST", ...Read now
Unlock full access