Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot stop the server #142

Open
zvolin opened this issue Mar 14, 2024 · 1 comment
Open

Cannot stop the server #142

zvolin opened this issue Mar 14, 2024 · 1 comment

Comments

@zvolin
Copy link

zvolin commented Mar 14, 2024

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
Copy link
Author

zvolin commented Mar 15, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant