Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5cb91d76 authored by Mike Yu's avatar Mike Yu
Browse files

Test: Make doh_unit_test boot_time::timeout_drift less flaky

On cuttlefish, `drift` is sometimes greater than 5ms. This is
probably due to cuttlefish being slow sometimes.

Run the test 200 times on cuttlefish with this change, the
distribution of these 2000 `drift`s is:
  7 out of 2000 over 5ms
  3 out of 2000 over 7ms
  1 out of 2000 over 9ms
  0 out of 2000 over 10ms.

The flaky rate of the test will be less than 0.5% theoretically

Bug: 261906096
Test: run boot_time::timeout_drift 200 times
Change-Id: Ia1c124f58b388357d4b0f96d5c06bce8ab739355
parent 19b5229f
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -195,21 +195,21 @@ fn round_trip() {

#[tokio::test]
async fn timeout_drift() {
    let delta = Duration::from_millis(20);
    for _ in 0..10 {
    let delta = Duration::from_millis(40);
    for _ in 0..5 {
        let start = BootTime::now();
        assert!(timeout(delta, pending::<()>()).await.is_err());
        let taken = start.elapsed();
        let drift = if taken > delta { taken - delta } else { delta - taken };
        assert!(drift < Duration::from_millis(5));
        assert!(drift < Duration::from_millis(10));
    }

    for _ in 0..10 {
    for _ in 0..5 {
        let start = BootTime::now();
        sleep(delta).await;
        let taken = start.elapsed();
        let drift = if taken > delta { taken - delta } else { delta - taken };
        assert!(drift < Duration::from_millis(5));
        assert!(drift < Duration::from_millis(10));
    }
}