Skip to content

Commit

Permalink
m
Browse files Browse the repository at this point in the history
  • Loading branch information
bmwill committed Jul 25, 2024
1 parent 89c1e36 commit c626117
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 39 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion consensus/core/src/network/tonic_network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -895,10 +895,13 @@ impl<S: NetworkService> NetworkManager<S> for TonicManager {
},
_ = shutdown_notif.wait(), if !has_shutdown => {
trace!("Received shutdown. Stopping connection for {peer_addr:?}");
connection.as_mut().graceful_shutdown();
has_shutdown = true;
},
}

if has_shutdown {
break;
}
}

Ok(())
Expand Down
1 change: 1 addition & 0 deletions crates/sui-storage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ move-binary-format.workspace = true
move-bytecode-utils.workspace = true

[dev-dependencies]
axum.workspace = true
anyhow.workspace = true
criterion.workspace = true
tempfile.workspace = true
Expand Down
60 changes: 22 additions & 38 deletions crates/sui-storage/tests/key_value_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,13 +428,9 @@ async fn test_get_tx_from_fallback() {

#[cfg(msim)]
mod simtests {

use super::*;
use hyper::{
service::{make_service_fn, service_fn},
Body, Request, Response, Server,
};
use std::convert::Infallible;
use axum::routing::get;
use axum::{body::Body, extract::Request, extract::State, response::Response};
use std::net::SocketAddr;
use std::sync::Mutex;
use std::time::{Duration, Instant};
Expand All @@ -443,6 +439,23 @@ mod simtests {
use sui_storage::http_key_value_store::*;
use tracing::info;

async fn svc(
State(state): State<Arc<Mutex<HashMap<String, Vec<u8>>>>>,
request: Request<Body>,
) -> Response {
let path = request.uri().path().to_string();
let key = path.trim_start_matches('/');
let value = state.lock().unwrap().get(key).cloned();
info!("Got request for key: {:?}, value: {:?}", key, value);
match value {
Some(v) => Response::new(Body::from(v)),
None => Response::builder()
.status(hyper::StatusCode::NOT_FOUND)
.body(Body::empty())
.unwrap(),
}
}

async fn test_server(data: Arc<Mutex<HashMap<String, Vec<u8>>>>) {
let handle = sui_simulator::runtime::Handle::current();
let builder = handle.create_node();
Expand All @@ -456,41 +469,12 @@ mod simtests {
let data = data.clone();
let startup_sender = startup_sender.clone();
async move {
let make_svc = make_service_fn(move |_| {
let data = data.clone();
async {
Ok::<_, Infallible>(service_fn(move |req: Request<Body>| {
let data = data.clone();
async move {
let path = req.uri().path().to_string();
let key = path.trim_start_matches('/');
let value = data.lock().unwrap().get(key).cloned();
info!("Got request for key: {:?}, value: {:?}", key, value);
match value {
Some(v) => {
Ok::<_, Infallible>(Response::new(Body::from(v)))
}
None => Ok::<_, Infallible>(
Response::builder()
.status(hyper::StatusCode::NOT_FOUND)
.body(Body::empty())
.unwrap(),
),
}
}
}))
}
});

let router = get(svc).with_state(data);
let addr = SocketAddr::from(([10, 10, 10, 10], 8080));
let server = Server::bind(&addr).serve(make_svc);

let graceful = server.with_graceful_shutdown(async {
tokio::time::sleep(Duration::from_secs(86400)).await;
});
let listener = tokio::net::TcpListener::bind(addr).await.unwrap();

tokio::spawn(async {
let _ = graceful.await;
axum::serve(listener, router).await.unwrap();
});

startup_sender.send(true).ok();
Expand Down

0 comments on commit c626117

Please sign in to comment.