Skip to content
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
14 changes: 14 additions & 0 deletions src/irmaclient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,20 @@ impl IrmaClient {
status => Err(Error::SessionNotFinished(status)),
}
}

/// Check whether the irma server is healthy and ready to serve sessions.
///
/// Issues `GET {base}/health` (added in irmago v0.15.0) and returns
/// `Ok(())` on a 2xx response, or [`Error::NetworkError`] otherwise.
/// Useful as a liveness/readiness check before starting a session.
pub async fn health(&self) -> Result<(), Error> {
self.client
.get(self.url.join("health")?)
.send()
.await?
.error_for_status()?;
Ok(())
}
}

/// Builder for IRMA clients
Expand Down
48 changes: 48 additions & 0 deletions tests/test_health.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use std::process::Stdio;

use irmars::IrmaClient;
use serial_test::serial;
use tokio::{
io::{AsyncBufReadExt, BufReader},
process::Command,
};

#[test]
#[serial]
fn test_health() {
if option_env!("RUN_INTEGRATION_TESTS").is_some() {
tokio_test::block_on(async {
let mut irmaserver = Command::new("irma")
.arg("server")
.stderr(Stdio::piped())
.spawn()
.expect("Could not start irma server");

let irmaserver_stderr = irmaserver
.stderr
.take()
.expect("No stderr available from irma server");
let mut irmaserver_lines = BufReader::new(irmaserver_stderr).lines();
loop {
let line = irmaserver_lines
.next_line()
.await
.expect("Error reading from irma server stderr")
.expect("No line recieved");
if line.contains("Server listening") {
break;
}
}

println!("Server started");

// Create an irma client
let client = IrmaClient::new("http://localhost:8088/").unwrap();

// A running server should report itself as healthy.
client.health().await.expect("Health check failed");

irmaserver.kill().await.expect("Error killing irma server");
});
}
}
Loading