Skip to content

Commit

Permalink
fix(test): fix CLI shutdown
Browse files Browse the repository at this point in the history
Fixes #767
  • Loading branch information
jhult committed Jul 17, 2024
1 parent 47287be commit f79b963
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 19 deletions.
6 changes: 4 additions & 2 deletions rust/src/bin/mina-indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use mina_indexer::{
initialize_indexer_database, start_indexer, IndexerConfiguration, InitializationMode,
},
store::{restore_snapshot, version::IndexerStoreVersion, IndexerStore},
unix_socket_server::remove_unix_socket,
web::start_web_server,
};
use std::{
Expand Down Expand Up @@ -287,7 +288,7 @@ impl ServerCommand {
check_or_write_pid_file(&database_dir);

debug!("Building mina indexer configuration");
let config = process_indexer_configuration(args, mode, domain_socket_path)?;
let config = process_indexer_configuration(args, mode, domain_socket_path.clone())?;

debug!("Creating a new mina indexer database in {database_dir:#?}");
let db = Arc::new(IndexerStore::new(&database_dir)?);
Expand All @@ -302,11 +303,12 @@ impl ServerCommand {
start_web_server(s, store, (web_hostname, web_port))
}));

info!("Shutting down primary database instance");
subsys.on_shutdown_requested().await;
info!("Shutting down primary database instance");
db.database.cancel_all_background_work(true);
remove_pid(&database_dir);
drop(db);
remove_unix_socket(&domain_socket_path)?;
Ok(())
}
}
Expand Down
1 change: 0 additions & 1 deletion rust/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ pub async fn start_indexer(
)
.await?;

subsys.on_shutdown_requested().await;
Ok(())
}

Expand Down
9 changes: 1 addition & 8 deletions rust/src/unix_socket_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ pub async fn handle_connection(
bail!("Unable to get a handle on indexer store...");
};

let local_addr = &connection.local_addr()?;
let command = parse_conn_to_cli(&connection).await?;
let (_, mut writer) = connection.into_split();

Expand Down Expand Up @@ -978,12 +977,6 @@ pub async fn handle_connection(
.write_all(b"Shutting down the Mina Indexer daemon...")
.await?;
subsys.request_shutdown();
remove_unix_socket(
local_addr
.as_pathname()
.expect("Unable to locate Unix domain socket file"),
)
.expect("Unix domain socket file deleted");
return Ok(());
}
ClientCli::Summary {
Expand Down Expand Up @@ -1242,7 +1235,7 @@ fn try_replace_old_socket(e: io::Error, unix_socket_path: &Path) -> io::Result<U
}
}

fn remove_unix_socket(unix_socket_path: &Path) -> io::Result<()> {
pub fn remove_unix_socket(unix_socket_path: &Path) -> io::Result<()> {
std::fs::remove_file(unix_socket_path)?;
debug!("Removed Unix domain socket: {:?}", unix_socket_path);
Ok(())
Expand Down
15 changes: 7 additions & 8 deletions tests/regression.bash
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ wait_forever_for_socket() {
}

idxr_server() {
idxr server "$@" &
RUST_BACKTRACE=full "$IDXR" --socket ./mina-indexer.sock server "$@" &
echo $! > ./idxr_pid
}

Expand Down Expand Up @@ -1384,8 +1384,8 @@ test_clean_kill() {
return 1
fi

echo " Sending Mina Indexer a SIGTERM"
PID="$(cat ./idxr_pid)"
echo " Sending Mina Indexer (PID $PID) a SIGTERM"
kill "$PID"

# We must give the process a chance to die cleanly.
Expand All @@ -1402,12 +1402,11 @@ test_clean_kill() {
return 1
fi

# TODO: robinbb - this is commented out because it does not pass!
# # Check for socket deletion.
# if [ -S ./mina-indexer.sock ]; then
# echo " The signal handler did not delete the socket. Failure."
# return 1
# fi
# Check for socket deletion.
if [ -S ./mina-indexer.sock ]; then
echo " The signal handler did not delete the socket. Failure."
return 1
fi
}

test_block_children() {
Expand Down

0 comments on commit f79b963

Please sign in to comment.