Commit e1d1fe65 authored by Ian Jackson's avatar Ian Jackson
Browse files

DownloadSchedule: tests: Do not try to set parallelism to 0

The current behaviour is to treat 0 as indicating "use the default",
which is quite strange.  We are going to get rid of that.

The new way will be to reject zero, during
DownloadScheduleBuilder::build, Add a test case for that.
parent a720205d
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -391,10 +391,10 @@ mod test {
        bld.retry_consensus(DownloadSchedule::new(7, Duration::new(86400, 0), 1))
            .retry_bootstrap(DownloadSchedule::new(4, Duration::new(3600, 0), 1))
            .retry_certs(DownloadSchedule::new(5, Duration::new(3600, 0), 1))
            .retry_microdescs(DownloadSchedule::new(6, Duration::new(3600, 0), 0));
            .retry_microdescs(DownloadSchedule::new(6, Duration::new(3600, 0), 1));

        let cfg = bld.build().unwrap();
        assert_eq!(cfg.retry_microdescs().parallelism(), 1); // gets clamped
        assert_eq!(cfg.retry_microdescs().parallelism(), 1);
        assert_eq!(cfg.retry_microdescs().n_attempts(), 6);
        assert_eq!(cfg.retry_bootstrap().n_attempts(), 4);
        assert_eq!(cfg.retry_consensus().n_attempts(), 7);
+9 −11
Original line number Diff line number Diff line
@@ -141,7 +141,6 @@ mod test {
        // default configuration is 3 tries, 1000 msec initial delay
        let cfg = DownloadSchedule::default();
        let one_sec = Duration::from_secs(1);
        let zero_sec = Duration::from_secs(0);
        let mut rng = rand::thread_rng();

        assert_eq!(cfg.n_attempts(), 3);
@@ -152,15 +151,14 @@ mod test {
        let mut sched = cfg.schedule();
        assert_eq!(sched.next_delay(&mut rng), one_sec);

        // Try a zero-attempt schedule, and have it get remapped to 1,1
        let cfg = DownloadSchedule::new(0, zero_sec, 0);
        assert_eq!(cfg.n_attempts(), 1);
        assert_eq!(cfg.parallelism(), 1);
        let v: Vec<_> = cfg.attempts().collect();
        assert_eq!(&v[..], &[0]);

        assert_eq!(cfg.initial_delay, zero_sec);
        let mut sched = cfg.schedule();
        assert_eq!(sched.next_delay(&mut rng), one_sec);
        // Try schedules with zeroes and show that they fail
        DownloadSchedule::builder()
            .attempts(0)
            .build()
            .expect_err("built with 0 retries");
        DownloadSchedule::builder()
            .parallelism(0)
            .build()
            .expect_err("built with 0 parallelism");
    }
}