File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -142,6 +142,20 @@ impl IrmaClient {
142142 status => Err ( Error :: SessionNotFinished ( status) ) ,
143143 }
144144 }
145+
146+ /// Check whether the irma server is healthy and ready to serve sessions.
147+ ///
148+ /// Issues `GET {base}/health` (added in irmago v0.15.0) and returns
149+ /// `Ok(())` on a 2xx response, or [`Error::NetworkError`] otherwise.
150+ /// Useful as a liveness/readiness check before starting a session.
151+ pub async fn health ( & self ) -> Result < ( ) , Error > {
152+ self . client
153+ . get ( self . url . join ( "health" ) ?)
154+ . send ( )
155+ . await ?
156+ . error_for_status ( ) ?;
157+ Ok ( ( ) )
158+ }
145159}
146160
147161/// Builder for IRMA clients
Original file line number Diff line number Diff line change 1+ use std:: process:: Stdio ;
2+
3+ use irmars:: IrmaClient ;
4+ use serial_test:: serial;
5+ use tokio:: {
6+ io:: { AsyncBufReadExt , BufReader } ,
7+ process:: Command ,
8+ } ;
9+
10+ #[ test]
11+ #[ serial]
12+ fn test_health ( ) {
13+ if option_env ! ( "RUN_INTEGRATION_TESTS" ) . is_some ( ) {
14+ tokio_test:: block_on ( async {
15+ let mut irmaserver = Command :: new ( "irma" )
16+ . arg ( "server" )
17+ . stderr ( Stdio :: piped ( ) )
18+ . spawn ( )
19+ . expect ( "Could not start irma server" ) ;
20+
21+ let irmaserver_stderr = irmaserver
22+ . stderr
23+ . take ( )
24+ . expect ( "No stderr available from irma server" ) ;
25+ let mut irmaserver_lines = BufReader :: new ( irmaserver_stderr) . lines ( ) ;
26+ loop {
27+ let line = irmaserver_lines
28+ . next_line ( )
29+ . await
30+ . expect ( "Error reading from irma server stderr" )
31+ . expect ( "No line recieved" ) ;
32+ if line. contains ( "Server listening" ) {
33+ break ;
34+ }
35+ }
36+
37+ println ! ( "Server started" ) ;
38+
39+ // Create an irma client
40+ let client = IrmaClient :: new ( "http://localhost:8088/" ) . unwrap ( ) ;
41+
42+ // A running server should report itself as healthy.
43+ client. health ( ) . await . expect ( "Health check failed" ) ;
44+
45+ irmaserver. kill ( ) . await . expect ( "Error killing irma server" ) ;
46+ } ) ;
47+ }
48+ }
You can’t perform that action at this time.
0 commit comments