Skip to content

Commit

Permalink
fix(s2n-quic-core): check weighted_average difference based on weight…
Browse files Browse the repository at this point in the history
… in nanos (#1501)
  • Loading branch information
camshaft authored Sep 21, 2022
1 parent c74f3da commit 08a08af
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions quic/s2n-quic-core/src/recovery/rtt_estimator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -728,10 +728,17 @@ mod test {

let weight = 8;

// assert that the unoptimized version matches the optimized to the millisecond
// perform the unoptimized version
let expected = ((weight - 1) as u32 * a) / weight + b / weight;
let actual = super::weighted_average(a, b, weight as _);
assert_eq!(expected.as_millis(), actual.as_millis());

// assert that the unoptimized result matches the optimized to the nearest `weight` nanos
assert!(
super::abs_difference(expected.as_nanos(), actual.as_nanos()) as u32 <= weight,
"expected: {:?}; actual: {:?}",
expected,
actual
);
})
}
}

0 comments on commit 08a08af

Please sign in to comment.