Skip to content

Commit

Permalink
chore: Add 100ms delay to give the mock server event loop time to com…
Browse files Browse the repository at this point in the history
…plete on shutdown
  • Loading branch information
rholshausen committed Jun 18, 2024
1 parent 89944a4 commit 47559ee
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 6 additions & 0 deletions pact_mock_server/src/hyper_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::fmt;
use std::fmt::{Display, Formatter};
use std::net::SocketAddr;
#[cfg(feature = "tls")] use std::sync::Arc;
use std::time::Duration;

#[allow(unused_imports)] use anyhow::anyhow;
use bytes::Bytes;
Expand Down Expand Up @@ -38,6 +39,7 @@ use tokio::select;
use tokio::sync::{mpsc, oneshot};
use tokio::sync::mpsc::Sender;
use tokio::task::JoinSet;
use tokio::time::sleep;
#[cfg(feature = "tls")] use tokio_rustls::TlsAcceptor;
use tracing::{debug, error, info, trace, warn};

Expand Down Expand Up @@ -127,6 +129,8 @@ pub(crate) async fn create_and_bind(
_ = &mut shutdown_recv => {
debug!("Received shutdown signal, waiting for existing connections to complete");
while let Some(_) = join_set.join_next().await {};
debug!("Waiting for event loop to complete");
sleep(Duration::from_millis(100)).await;
debug!("Existing connections complete, exiting main loop");
drop(event_send);
break;
Expand Down Expand Up @@ -232,6 +236,8 @@ pub(crate) async fn create_and_bind_https(
_ = &mut shutdown_recv => {
debug!("Received shutdown signal, waiting for existing connections to complete");
while let Some(_) = join_set.join_next().await {};
debug!("Waiting for event loop to complete");
sleep(Duration::from_millis(100)).await;
debug!("Existing connections complete, exiting main loop");
drop(event_send);
break;
Expand Down
5 changes: 3 additions & 2 deletions pact_mock_server/src/mock_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,12 @@ impl MockServer {

/// Send the shutdown signal to the server
pub fn shutdown(&self) -> anyhow::Result<()> {
let shutdown_future = self.shutdown_tx.take();
match shutdown_future {
let shutdown = self.shutdown_tx.take();
match shutdown {
Some(sender) => {
match sender.send(()) {
Ok(()) => {

let metrics = {
let guard = self.metrics.lock().unwrap();
guard.clone()
Expand Down

0 comments on commit 47559ee

Please sign in to comment.