feat: remove retrieval batch over HTTP
This commit is contained in:
@@ -9,11 +9,9 @@ use std::time::{Duration, Instant};
|
||||
use tempfile::tempdir;
|
||||
use wip_fs_server::{AccessMode, ServerConfig, WipFsServer};
|
||||
use wip_http::{
|
||||
BatchRequest, BatchRequestItem, BatchRequestKind, BatchResponse, BatchSuccess,
|
||||
ClientResponseError, DecodedResponse, Endpoint, JSON_CONTENT_TYPE, Limits, Route,
|
||||
TransportFailureKind, decode_batch_request, decode_batch_response,
|
||||
decode_call_operation_response, decode_fetch_interface_response, decode_observe_response,
|
||||
encode_batch_request, encode_call_operation_request, encode_fetch_interface_request,
|
||||
TransportFailureKind, decode_call_operation_response, decode_fetch_interface_response,
|
||||
decode_observe_response, encode_call_operation_request, encode_fetch_interface_request,
|
||||
encode_observe_request,
|
||||
};
|
||||
use wip_protocol::{
|
||||
@@ -22,7 +20,7 @@ use wip_protocol::{
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn real_listener_serves_three_core_interactions_batch_and_write() {
|
||||
fn real_listener_serves_three_core_interactions_and_write() {
|
||||
let temporary = tempdir().expect("temporary root");
|
||||
std::fs::write(temporary.path().join("hello.txt"), b"hello world").expect("write file");
|
||||
std::fs::create_dir(temporary.path().join("nested")).expect("create directory");
|
||||
@@ -125,36 +123,6 @@ fn real_listener_serves_three_core_interactions_batch_and_write() {
|
||||
);
|
||||
assert_eq!(read.result, Value::Bytes(b"world".to_vec()));
|
||||
|
||||
let batch_request = BatchRequest {
|
||||
requests: vec![
|
||||
BatchRequestItem {
|
||||
id: "root".into(),
|
||||
request: BatchRequestKind::Observe(ObserveRequest {
|
||||
path: "/".into(),
|
||||
depth: 0,
|
||||
}),
|
||||
},
|
||||
BatchRequestItem {
|
||||
id: "tree".into(),
|
||||
request: BatchRequestKind::Observe(ObserveRequest {
|
||||
path: "/nested".into(),
|
||||
depth: 1,
|
||||
}),
|
||||
},
|
||||
BatchRequestItem {
|
||||
id: "interface".into(),
|
||||
request: BatchRequestKind::FetchInterface(read_interface_request.clone()),
|
||||
},
|
||||
],
|
||||
};
|
||||
let response = exchange(
|
||||
address,
|
||||
encode_batch_request(&endpoint, &batch_request, limits).expect("encode batch"),
|
||||
);
|
||||
let batch =
|
||||
success(decode_batch_response(&batch_request, &response, limits).expect("decode batch"));
|
||||
assert_batch_successes(&batch);
|
||||
|
||||
let write_interface_request = FetchInterfaceRequest {
|
||||
interface: file.interfaces[1].clone(),
|
||||
};
|
||||
@@ -215,7 +183,7 @@ fn real_listener_serves_three_core_interactions_batch_and_write() {
|
||||
fn real_listener_keeps_route_method_and_malformed_body_boundaries_distinct() {
|
||||
let temporary = tempdir().expect("temporary root");
|
||||
let mut config = ServerConfig::for_root(temporary.path());
|
||||
config.limits.wire = Limits::new(64, 4_096, 64, 4).expect("wire limits");
|
||||
config.limits.wire = Limits::new(64, 4_096, 64).expect("wire limits");
|
||||
let bound = Arc::new(
|
||||
WipFsServer::new(config)
|
||||
.expect("build server")
|
||||
@@ -232,6 +200,7 @@ fn real_listener_keeps_route_method_and_malformed_body_boundaries_distinct() {
|
||||
|
||||
for uri in [
|
||||
"/wip/v1/unknown",
|
||||
"/wip/v1/batch",
|
||||
"/wip/v1/observe?unexpected=true",
|
||||
"/wip/v1/observe/extra",
|
||||
] {
|
||||
@@ -239,6 +208,7 @@ fn real_listener_keeps_route_method_and_malformed_body_boundaries_distinct() {
|
||||
assert_eq!(response.status(), http::StatusCode::NOT_FOUND);
|
||||
assert!(response.body().is_empty());
|
||||
assert!(!response.headers().contains_key(http::header::CONTENT_TYPE));
|
||||
assert!(!response.headers().contains_key(http::header::ALLOW));
|
||||
}
|
||||
|
||||
let wrong_method = exchange(
|
||||
@@ -326,10 +296,10 @@ fn real_listener_keeps_route_method_and_malformed_body_boundaries_distinct() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn raw_decoder_and_batch_packaging_limits_are_transport_failures() {
|
||||
fn raw_decoder_limits_are_transport_failures() {
|
||||
let temporary = tempdir().expect("temporary root");
|
||||
let mut config = ServerConfig::for_root(temporary.path());
|
||||
config.limits.wire = Limits::new(4_096, 4_096, 8, 1).expect("wire limits");
|
||||
config.limits.wire = Limits::new(4_096, 4_096, 8).expect("wire limits");
|
||||
let server = WipFsServer::new(config).expect("build server");
|
||||
|
||||
let nested = br#"{"path":[[[[[[[[["/"]]]]]]]]],"depth":0}"#;
|
||||
@@ -337,12 +307,6 @@ fn raw_decoder_and_batch_packaging_limits_are_transport_failures() {
|
||||
assert_eq!(response.status(), http::StatusCode::PAYLOAD_TOO_LARGE);
|
||||
assert!(response.body().is_empty());
|
||||
assert!(!response.headers().contains_key(http::header::CONTENT_TYPE));
|
||||
|
||||
let batch = br#"{"requests":[{"id":"one","method":"observe","arguments":{"path":"/","depth":0}},{"id":"two","method":"observe","arguments":{"path":"/","depth":0}}]}"#;
|
||||
let response = server.handle_http(json_request(http::Method::POST, "/wip/v1/batch", batch));
|
||||
assert_eq!(response.status(), http::StatusCode::PAYLOAD_TOO_LARGE);
|
||||
assert!(response.body().is_empty());
|
||||
assert!(!response.headers().contains_key(http::header::CONTENT_TYPE));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -442,37 +406,6 @@ fn stalled_request_body_times_out_and_releases_the_only_worker() {
|
||||
.expect("listener exits cleanly");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn batch_keeps_known_malformed_arguments_item_local() {
|
||||
let temporary = tempdir().expect("temporary root");
|
||||
let config = ServerConfig::for_root(temporary.path());
|
||||
let limits = config.limits.wire;
|
||||
let server = WipFsServer::new(config).expect("build server");
|
||||
let endpoint = Endpoint::parse("http://localhost/wip").expect("endpoint");
|
||||
let body = br#"{"requests":[{"id":"ok","method":"observe","arguments":{"path":"/","depth":0}},{"id":"bad","method":"observe","arguments":{"path":"/","depth":"bad"}}]}"#;
|
||||
let logical = decode_batch_request(body, limits).expect("decode item-local invalid request");
|
||||
assert!(matches!(
|
||||
logical.requests[1].request,
|
||||
BatchRequestKind::Invalid { .. }
|
||||
));
|
||||
let request = http::Request::builder()
|
||||
.method(http::Method::POST)
|
||||
.uri(endpoint.route(Route::Batch).as_str())
|
||||
.header(http::header::CONTENT_TYPE, JSON_CONTENT_TYPE)
|
||||
.header(http::header::ACCEPT, "application/json")
|
||||
.body(body.to_vec())
|
||||
.expect("build request");
|
||||
let response = server.handle_http(request);
|
||||
let batch = success(
|
||||
decode_batch_response(&logical, &response, limits).expect("decode mixed batch response"),
|
||||
);
|
||||
assert!(matches!(
|
||||
batch.responses[0].outcome,
|
||||
Ok(BatchSuccess::Observe(_))
|
||||
));
|
||||
assert!(batch.responses[1].outcome.is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn call_argument_decoding_does_not_mask_missing_target() {
|
||||
let temporary = tempdir().expect("temporary root");
|
||||
@@ -524,7 +457,7 @@ fn read_response_size_failure_is_transport_local() {
|
||||
let temporary = tempdir().expect("temporary root");
|
||||
std::fs::write(temporary.path().join("large"), vec![b'x'; 2_000]).expect("write file");
|
||||
let mut config = ServerConfig::for_root(temporary.path());
|
||||
config.limits.wire = Limits::new(4_096, 1_024, 64, 64).expect("wire limits");
|
||||
config.limits.wire = Limits::new(4_096, 1_024, 64).expect("wire limits");
|
||||
let limits = config.limits.wire;
|
||||
let server = WipFsServer::new(config).expect("build server");
|
||||
let endpoint = Endpoint::parse("http://localhost/wip").expect("endpoint");
|
||||
@@ -579,22 +512,6 @@ fn read_response_size_failure_is_transport_local() {
|
||||
));
|
||||
}
|
||||
|
||||
fn assert_batch_successes(batch: &BatchResponse) {
|
||||
assert_eq!(batch.responses.len(), 3);
|
||||
assert!(matches!(
|
||||
batch.responses[0].outcome,
|
||||
Ok(BatchSuccess::Observe(_))
|
||||
));
|
||||
assert!(matches!(
|
||||
batch.responses[1].outcome,
|
||||
Ok(BatchSuccess::Observe(_))
|
||||
));
|
||||
assert!(matches!(
|
||||
batch.responses[2].outcome,
|
||||
Ok(BatchSuccess::FetchInterface(_))
|
||||
));
|
||||
}
|
||||
|
||||
fn success<T>(response: DecodedResponse<T>) -> T {
|
||||
match response {
|
||||
DecodedResponse::Success(value) => value,
|
||||
|
||||
Reference in New Issue
Block a user