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

chore: add tests related to communication with dead processes. #22

Merged
merged 2 commits into from
Jan 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions geth-engine/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ mod echo;
pub mod grpc;
pub mod indexing;
mod messages;
#[cfg(test)]
mod panic;
pub mod reading;
mod resource;
#[cfg(test)]
Expand Down Expand Up @@ -69,6 +71,8 @@ pub enum Proc {
Echo,
#[cfg(test)]
Sink,
#[cfg(test)]
Panic,
}

enum Topology {
Expand Down Expand Up @@ -281,6 +285,9 @@ where

#[cfg(test)]
Proc::Sink => spawn(options, client, proc, sink::run),

#[cfg(test)]
Proc::Panic => spawn(options, client, proc, panic::run),
};

let proc_id = running_proc.id;
Expand Down
7 changes: 7 additions & 0 deletions geth-engine/src/process/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ pub enum Messages {
Responses(Responses),
}

#[cfg(test)]
impl Messages {
pub fn is_fatal_error(&self) -> bool {
matches!(self, Messages::Responses(Responses::FatalError))
}
}

impl From<IndexRequests> for Messages {
fn from(req: IndexRequests) -> Self {
Messages::Requests(Requests::Index(req))
Expand Down
5 changes: 5 additions & 0 deletions geth-engine/src/process/panic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use super::ProcessEnv;

pub async fn run(_: ProcessEnv) -> eyre::Result<()> {
panic!("this process panic on purpose");
}
29 changes: 29 additions & 0 deletions geth-engine/src/process/tests/interactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ fn test_catalog() -> Catalog {
Catalog::builder()
.register(Proc::Echo)
.register(Proc::Sink)
.register(Proc::Panic)
.build()
}

Expand Down Expand Up @@ -90,3 +91,31 @@ async fn test_shutdown_reported_properly() -> eyre::Result<()> {

Ok(())
}

#[tokio::test]
async fn test_request_returns_when_proc_panicked() -> eyre::Result<()> {
let manager = start_process_manager_with_catalog(Options::in_mem(), test_catalog()).await?;
let proc_id = manager.wait_for(Proc::Panic).await?;

let resp = manager
.request(proc_id, TestSinkResponses::Stream(42).into())
.await?;

assert!(resp.payload.is_fatal_error());

Ok(())
}

#[tokio::test]
async fn test_stream_returns_when_proc_panicked() -> eyre::Result<()> {
let manager = start_process_manager_with_catalog(Options::in_mem(), test_catalog()).await?;
let proc_id = manager.wait_for(Proc::Panic).await?;

let mut resp = manager
.request_stream(proc_id, TestSinkResponses::Stream(42).into())
.await?;

assert!(resp.recv().await.is_none());

Ok(())
}
Loading