wiremock-rs icon indicating copy to clipboard operation
wiremock-rs copied to clipboard

Cannot stop the server

Open zvolin opened this issue 1 year ago • 1 comments

Hey, as in issue title. I wanted to test that a service gracefully handles networking issues like server being temporarily unreachable and wanted to do that by dropping the MockServer, however this loop actually never finishes:

use std::time::Duration;

use tokio::{net::TcpStream, time::sleep};
use wiremock::MockServer;

#[tokio::main]
async fn main() {
    let server = MockServer::start().await;
    let addr = *server.address();

    drop(server);

    loop {
        if TcpStream::connect(addr).await.is_err() {
            break;
        }
        sleep(Duration::from_millis(200)).await;
        println!("retrying");
    }
}

zvolin avatar Mar 14 '24 19:03 zvolin

Wanted to work on this issue and it turned out that this bug is actually an undocumented feature. I found this comment too

/// `wiremock`'s pooling is designed to be an invisible optimisation: users of the crate, if
/// we are successful, should never have to reason about it.

Would you consider a PR which mentions about the difference in behavior on MockServer::start and MockServer::builder? Builder avoids pooling and was what I was actually looking for in this particular test, but I had to find it out by reading code

zvolin avatar Mar 15 '24 13:03 zvolin