@@ -14,7 +14,7 @@ use tokio::io::AsyncReadExt;
14
14
use axum:: http:: { Uri , uri:: Scheme } ;
15
15
use chrono:: Utc ;
16
16
use futures:: TryStreamExt ;
17
- use log:: { error , info} ;
17
+ use log:: info;
18
18
use reqwest:: { Client , StatusCode } ;
19
19
use sarlacc:: Intern ;
20
20
use tokio:: sync:: RwLock ;
@@ -84,30 +84,32 @@ async fn is_online() -> bool {
84
84
85
85
/// Checks whether a given URL passes the given check level.
86
86
///
87
- /// Returns `Some` with the failure details if the site fails the check, or `None` if it passes (or
88
- /// if the check cannot be performed, e.g., due to the server being offline).
87
+ /// Returns `Ok(Some(...))` with the failure details if the site fails the check, or `Ok(None)` if it passes.
88
+ ///
89
+ /// Returns `Err` if the check cannot be performed (e.g., due to the server being offline).
89
90
pub async fn check (
90
91
website : & Uri ,
91
92
check_level : CheckLevel ,
92
93
base_address : Intern < Uri > ,
93
- ) -> Option < CheckFailure > {
94
+ ) -> Result < Option < CheckFailure > , ( ) > {
94
95
match check_impl ( website, check_level, base_address) . await {
95
- None => None ,
96
+ None => Ok ( None ) ,
96
97
Some ( failure) => {
97
98
// If the issue is not a connection issue, or if it is a connection issue and the
98
99
// server is online, return it. Otherwise, it's a connection issue on our end, so log
99
100
// and count the check as successful.
101
+ #[ cfg( not( test) ) ]
100
102
if let CheckFailure :: Connection ( connection_error) = & failure {
101
103
if !is_online ( ) . await {
102
- error ! (
104
+ log :: error!(
103
105
"Server-side connectivity issue detected: Could not reach {website}: {connection_error}"
104
106
) ;
105
- return None ;
107
+ return Err ( ( ) ) ;
106
108
}
107
109
}
108
110
109
111
info ! ( "{website} failed a check: {failure}" ) ;
110
- Some ( failure)
112
+ Ok ( Some ( failure) )
111
113
}
112
114
}
113
115
}
@@ -141,6 +143,7 @@ async fn check_impl(
141
143
Ok ( response) => response,
142
144
Err ( err) => return Some ( CheckFailure :: Connection ( err) ) ,
143
145
} ;
146
+ println ! ( "{response:?}" ) ;
144
147
mark_server_as_online ( ) . await ;
145
148
let successful_response = match response. error_for_status ( ) {
146
149
Ok ( r) => r,
@@ -604,7 +607,7 @@ mod tests {
604
607
#[ expect( clippy:: type_complexity) ]
605
608
let sites: Vec < ( Uri , Vec < CheckLevel > , fn ( CheckFailure ) -> bool ) > = vec ! [
606
609
(
607
- Uri :: from_static( "http://127.0.0.10:0 /connection" ) ,
610
+ Uri :: from_static( "http://127.0.0.10:60000 /connection" ) ,
608
611
vec![ CheckLevel :: None ] ,
609
612
|failure| matches!( failure, CheckFailure :: Connection ( _) ) ,
610
613
) ,
@@ -638,7 +641,7 @@ mod tests {
638
641
] ;
639
642
for level in levels {
640
643
// FIXME: Collect CheckFailure and check type
641
- let maybe_failure = super :: check ( & site, level, base) . await ;
644
+ let maybe_failure = super :: check ( & site, level, base) . await . unwrap ( ) ;
642
645
eprintln ! ( "Checking {} at level {:?}" , & site, level) ;
643
646
let was_successful = maybe_failure. is_none ( ) ;
644
647
assert_eq ! ( expect_passing. contains( & level) , was_successful) ;
@@ -662,6 +665,7 @@ mod tests {
662
665
assert ! (
663
666
check( & Uri :: from_static( "https://kasad.com" ) , level, base)
664
667
. await
668
+ . unwrap( )
665
669
. is_none( )
666
670
) ;
667
671
}
0 commit comments