memoryd: the Honcho worker sends conclusions, their deletions and fleet notes
Co-Authored-By: ornith-1.5-35b-a3b <agent@wntrmute.dev>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
//! A fake Honcho for tests, on 127.0.0.1 and a port of its own: it answers each request from the
|
||||
//! responses recorded from rift (`tests/fixtures/honcho/`), by method and path, and records every
|
||||
//! request, body included. It can be set to answer every request with a status instead, or to
|
||||
//! responses recorded from rift (`tests/fixtures/honcho/`), by method and path (a batch of
|
||||
//! messages or conclusions answered with as many as it asked for, up to the two recorded), and
|
||||
//! records every request, body included. It can be set to answer every request with a status instead, or to
|
||||
//! answer nothing. Stopped, and its held connections released, when dropped; every wait has a
|
||||
//! deadline. Do not edit.
|
||||
|
||||
@@ -214,8 +215,13 @@ fn answer(request: &Request, made: &Mutex<HashSet<String>>) -> (u16, String) {
|
||||
}
|
||||
("POST", ["v3", "workspaces", _, "sessions"]) => fixture("06-session-create.json"),
|
||||
("POST", ["v3", "workspaces", _, "sessions", _, "messages"]) => {
|
||||
fixture("08-messages-add-batch.json")
|
||||
first(fixture("08-messages-add-batch.json"), request, "messages")
|
||||
}
|
||||
("POST", ["v3", "workspaces", _, "conclusions"]) => first(
|
||||
fixture("11-conclusions-create-batch.json"),
|
||||
request,
|
||||
"conclusions",
|
||||
),
|
||||
("DELETE", ["v3", "workspaces", _, "conclusions", _]) if again => {
|
||||
fixture("16-conclusion-delete-again.json")
|
||||
}
|
||||
@@ -226,6 +232,19 @@ fn answer(request: &Request, made: &Mutex<HashSet<String>>) -> (u16, String) {
|
||||
}
|
||||
}
|
||||
|
||||
/// A recorded batch answer cut to as many items as the request's `field` holds (the recorded ones
|
||||
/// hold two), so that one message or conclusion gets one id.
|
||||
fn first(recorded: (u16, String), request: &Request, field: &str) -> (u16, String) {
|
||||
let asked = request
|
||||
.body
|
||||
.as_ref()
|
||||
.and_then(|b| b[field].as_array())
|
||||
.map_or(0, Vec::len);
|
||||
let mut items: Vec<Value> = serde_json::from_str(&recorded.1).unwrap();
|
||||
items.truncate(asked);
|
||||
(recorded.0, Value::Array(items).to_string())
|
||||
}
|
||||
|
||||
fn serve(mut stream: TcpStream, shared: &Shared) {
|
||||
let _ = stream.set_read_timeout(Some(Duration::from_secs(10)));
|
||||
let Some(request) = read_request(&mut stream) else {
|
||||
|
||||
Reference in New Issue
Block a user