Skip to content
Draft
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
21 changes: 17 additions & 4 deletions src/publication/sparql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,24 @@ impl<R: Read> Read for LimitedRead<R> {
Ok(n)
}
}
/// Converts a transport failure into an I/O error that names every cause.
///
/// `reqwest` reports connect failures, timeouts and dropped connections all as
/// "error sending request"; the distinguishing cause is only in the source
/// chain, so the chain is rendered rather than discarded.
pub(crate) fn http_error(error: reqwest::Error) -> io::Error {
io::Error::other(format!(
"SPARQL HTTP request failed: {}",
error.without_url()
))
let error = error.without_url();
let mut message = format!("SPARQL HTTP request failed: {error}");
let mut cause = std::error::Error::source(&error);
while let Some(inner) = cause {
message.push_str(": ");
message.push_str(&inner.to_string());
cause = inner.source();
}
if error.is_timeout() {
message.push_str(" (timed out)");
}
io::Error::other(message)
}
pub(crate) fn status(status: reqwest::StatusCode) -> io::Result<()> {
if status.is_success() {
Expand Down
47 changes: 46 additions & 1 deletion tests/sparql_support/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,22 @@ impl Server {
let state = shared.clone();
let base = origin.clone();
thread::spawn(move || {
if let Err(error) = serve(stream, &base, state)
let started = std::time::Instant::now();
let outcome = serve(stream, &base, state);
let elapsed = started.elapsed();
if elapsed > std::time::Duration::from_millis(250) ||
outcome.is_err()
{
let _ = std::io::Write::write_all(
&mut std::io::stderr(),
format!(
"DIAG mock request {elapsed:?} {:?}\n",
outcome.as_ref().err()
)
.as_bytes(),
);
}
if let Err(error) = outcome
&& !error.downcast_ref::<std::io::Error>().is_some_and(|e| matches!(e.kind(), std::io::ErrorKind::BrokenPipe | std::io::ErrorKind::ConnectionReset)) { panic!("{error:#}"); }
});
},
Expand Down Expand Up @@ -165,7 +180,24 @@ fn serve(
if delay > 0 {
thread::sleep(std::time::Duration::from_millis(delay));
}
let waited = std::time::Instant::now();
let mut state = state.lock().unwrap();
let wait = waited.elapsed();
if wait > std::time::Duration::from_millis(100) {
let _ = std::io::Write::write_all(
&mut std::io::stderr(),
format!("DIAG mock lock wait {wait:?} {method} {path}\n")
.as_bytes(),
);
}
let handling = std::time::Instant::now();
let _guard = Timing(
handling,
format!(
"{method} {path} quads={}",
state.store.len().unwrap_or(0)
),
);
state.authenticated |= headers
.to_ascii_lowercase()
.contains("authorization: bearer grapharch-test-only");
Expand Down Expand Up @@ -338,3 +370,16 @@ fn query_json(store: &Store, query: &str) -> Result<Vec<u8>> {
},
}
}

struct Timing(std::time::Instant, String);
impl Drop for Timing {
fn drop(&mut self) {
let e = self.0.elapsed();
if e > std::time::Duration::from_millis(100) {
let _ = std::io::Write::write_all(
&mut std::io::stderr(),
format!("DIAG mock handled {e:?} {}\n", self.1).as_bytes(),
);
}
}
}
Loading