One host under test, reached over HTTP: the same client for whiskersd, wrangler dev and celld dev.
3use std::time::{Duration, Instant};
The header that names a household in a host that was told to trust it (.dev.vars).
6pub const HOUSEHOLD_HEADER: &str = "x-whiskers-household";
What one request got back, as far as a device could tell.
A host's address and how to ask it things.
A request. method is any; household is sent as the household header.
35 pub fn send(&self, method: &str, path: &str, household: &str, body: &str) -> Result<Reply, String> { 36 let url = format!("{}{path}", self.base); 37 let request = ureq::http::Request::builder().method(method).uri(&url).header(HOUSEHOLD_HEADER, household); 38 let request = if method == "POST" { request.body(body.to_owned()) } else { request.body(String::new()) }.map_err(|e| e.to_string())?; 39 let mut response = self.agent.run(request).map_err(|e| format!("{method} {path}: {e}"))?; 40 let status = response.status().as_u16(); 41 let content_type = response.headers().get("content-type").and_then(|v| v.to_str().ok()).map(str::to_owned); 42 let body = response.body_mut().read_to_string().map_err(|e| format!("{method} {path}: reading the body: {e}"))?; 43 Ok(Reply { status, content_type, body }) 44 }
Waits until the host answers a sync, for after a restart.
51 pub fn wait_ready(&self, within: Duration) -> Result<Duration, String> { 52 let started = Instant::now(); 53 loop { 54 let probe = self.post("/memory/sync", "readiness-probe", r#"{"facts":[],"forgotten":[]}"#); 55 if matches!(probe, Ok(Reply { status: 200, .. })) { 56 return Ok(started.elapsed()); 57 } 58 if started.elapsed() > within { 59 return Err(format!("the host was not ready within {within:?}: {probe:?}")); 60 } 61 std::thread::sleep(Duration::from_millis(200)); 62 } 63 } 64}