refactor(client): separate accepted negotiation state from peer evidence
This commit is contained in:
32 files changed
+507
-447
No files matched your search
@@ -1,6 +1,6 @@
|
||||
use super::*;
|
||||
use irtt_client::NegotiationPolicy;
|
||||
use irtt_client::{NegotiatedParams, RunMode, WarningKind, MAX_UDP_PAYLOAD_LENGTH};
|
||||
use irtt_client::{NegotiationResult, RunMode, WarningKind, MAX_UDP_PAYLOAD_LENGTH};
|
||||
use irtt_proto::{flags, Params, TimestampFields};
|
||||
use irtt_proto::{
|
||||
flags::FLAG_HMAC, flags::FLAG_OPEN, flags::FLAG_REPLY, verify_packet_hmac, Clock, HMAC_SIZE,
|
||||
|
||||
@@ -60,24 +60,35 @@ fn no_test_strict_negotiation_rejects_changed_params() {
|
||||
|
||||
#[test]
|
||||
fn no_test_loose_negotiation_accepts_restricted_params() {
|
||||
let mut config = default_test_config();
|
||||
config.request.run_mode = RunMode::NoTest;
|
||||
config.open.negotiation = NegotiationPolicy::Loose;
|
||||
let requested = default_params();
|
||||
let mut params = requested.clone();
|
||||
params.duration_ns /= 2;
|
||||
let server = no_test_server(params.clone(), 0);
|
||||
let mut client = Client::connect(server.addr.to_string(), config).unwrap();
|
||||
let negotiated = assert_no_test_completed(client.open().unwrap());
|
||||
assert_eq!(negotiated.params, params);
|
||||
assert_eq!(
|
||||
negotiated.restrictions,
|
||||
vec![irtt_client::NegotiationRestriction::DurationReduced {
|
||||
requested_ns: requested.duration_ns,
|
||||
negotiated_ns: params.duration_ns,
|
||||
}]
|
||||
);
|
||||
server.join();
|
||||
for requested_duration in [Some(Duration::from_secs(3)), None] {
|
||||
let mut config = default_test_config();
|
||||
config.request.run_mode = RunMode::NoTest;
|
||||
config.request.duration = requested_duration;
|
||||
config.open.negotiation = NegotiationPolicy::Loose;
|
||||
let mut params = default_params();
|
||||
params.duration_ns = 1_500_000_000;
|
||||
let server = no_test_server(params.clone(), 0);
|
||||
let mut client = Client::connect(server.addr.to_string(), config).unwrap();
|
||||
let negotiated = assert_no_test_completed(client.open().unwrap());
|
||||
assert_eq!(negotiated.peer_params, params);
|
||||
assert_eq!(
|
||||
negotiated.accepted.duration,
|
||||
Some(Duration::from_millis(1500))
|
||||
);
|
||||
assert_eq!(
|
||||
negotiated.changes,
|
||||
vec![irtt_client::NegotiationChange::DurationReduced {
|
||||
requested: requested_duration,
|
||||
negotiated: Duration::from_millis(1500),
|
||||
}]
|
||||
);
|
||||
assert_eq!(
|
||||
client.negotiation(),
|
||||
None,
|
||||
"no-test creates no live session"
|
||||
);
|
||||
server.join();
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -222,33 +222,24 @@ pub(super) fn echo_server(params: Params) -> FakeServer {
|
||||
})
|
||||
}
|
||||
|
||||
pub(super) fn assert_open_started(outcome: OpenOutcome) -> NegotiatedParams {
|
||||
pub(super) fn assert_open_started(outcome: OpenOutcome) -> NegotiationResult {
|
||||
match outcome {
|
||||
OpenOutcome::Started {
|
||||
token, negotiated, ..
|
||||
} => {
|
||||
OpenOutcome::Started(irtt_client::SessionStarted {
|
||||
token,
|
||||
negotiation: negotiated,
|
||||
..
|
||||
}) => {
|
||||
assert_eq!(token, TOKEN);
|
||||
negotiated
|
||||
}
|
||||
OpenOutcome::NoTestCompleted { .. } => panic!("unexpected no-test outcome"),
|
||||
OpenOutcome::NoTestCompleted(_) => panic!("unexpected no-test outcome"),
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn assert_no_test_completed(outcome: OpenOutcome) -> NegotiatedParams {
|
||||
pub(super) fn assert_no_test_completed(outcome: OpenOutcome) -> NegotiationResult {
|
||||
match outcome {
|
||||
OpenOutcome::NoTestCompleted {
|
||||
negotiated, event, ..
|
||||
} => {
|
||||
assert!(matches!(
|
||||
event,
|
||||
ClientEvent::NoTestCompleted {
|
||||
negotiated: ref event_params,
|
||||
..
|
||||
} if *event_params == negotiated
|
||||
));
|
||||
negotiated
|
||||
}
|
||||
OpenOutcome::Started { .. } => panic!("unexpected started outcome"),
|
||||
OpenOutcome::NoTestCompleted(completed) => completed.negotiation,
|
||||
OpenOutcome::Started(_) => panic!("unexpected started outcome"),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user