async fn tune_sets_expected_values_and_then_waits() {
        let (handles, _) = setup_requester_test(None).await;

        let mut buckets = leaky_bucket::LeakyBuckets::new();
        let coordinator = buckets.coordinate().unwrap();
        tokio::spawn(async move { coordinator.await.expect("coordinator errored") });
        let limiter = buckets.rate_limiter().max(200).build().unwrap();

        let scan = FeroxScan::new(
            "http://localhost",
            ScanType::Directory,
            ScanOrder::Initial,
            1000,
            OutputLevel::Default,
            None,
        );
        scan.set_status(ScanStatus::Running).unwrap();
        scan.add_429();

        let requester = Requester {
            handles,
            seen_links: RwLock::new(HashSet::<String>::new()),
            tuning_lock: Mutex::new(0),
            ferox_scan: scan.clone(),
            target_url: "http://localhost".to_string(),
            rate_limiter: RwLock::new(Some(limiter)),
            policy_data: PolicyData::new(RequesterPolicy::AutoTune, 4),
        };

        let start = Instant::now();

        let pb = scan.progress_bar();
        pb.set_length(1000);
        pb.set_position(400);
        sleep(Duration::new(1, 0)).await; // used to get req/sec up to 400

        assert_eq!(requester.policy_data.errors.load(Ordering::Relaxed), 0);

        requester.tune(PolicyTrigger::Status429).await.unwrap();

        assert_eq!(requester.policy_data.heap.read().unwrap().original, 400);
        assert_eq!(requester.policy_data.get_limit(), 200);
        assert_eq!(
            requester.rate_limiter.read().await.as_ref().unwrap().max(),
            200
        );

        scan.finish().unwrap();
        assert!(start.elapsed().as_millis() >= 2000);
    }
/// tune should set req/sec and rate_limiter, adjust the limit and cooldown
tune should set req/sec and rate_limiter, adjust the limit and cooldown
tune should set req / sec and rate_limiter adjust the limit and cooldown
async fn tune_sets_expected_values_and_then_waits() {
        let (handles, _) = setup_requester_test(None).await;
        let mut buckets = leaky_bucket::LeakyBuckets::new();
        let coordinator = buckets.coordinate().unwrap();
        tokio::spawn(async move { coordinator.await.expect("coordinator errored") });
        let limiter = buckets.rate_limiter().max(200).build().unwrap();
        let scan = FeroxScan::new(
            "http://localhost",
            ScanType::Directory,
            ScanOrder::Initial,
            1000,
            OutputLevel::Default,
            None,
        );
        scan.set_status(ScanStatus::Running).unwrap();
        scan.add_429();
        let requester = Requester {
            handles,
            seen_links: RwLock::new(HashSet::<String>::new()),
            tuning_lock: Mutex::new(0),
            ferox_scan: scan.clone(),
            target_url: "http://localhost".to_string(),
            rate_limiter: RwLock::new(Some(limiter)),
            policy_data: PolicyData::new(RequesterPolicy::AutoTune, 4),
        };
        let start = Instant::now();
        let pb = scan.progress_bar();
        pb.set_length(1000);
        pb.set_position(400);
        sleep(Duration::new(1, 0)).await; // used to get req/sec up to 400
        assert_eq!(requester.policy_data.errors.load(Ordering::Relaxed), 0);
        requester.tune(PolicyTrigger::Status429).await.unwrap();
        assert_eq!(requester.policy_data.heap.read().unwrap().original, 400);
        assert_eq!(requester.policy_data.get_limit(), 200);
        assert_eq!(
            requester.rate_limiter.read().await.as_ref().unwrap().max(),
            200
        );
        scan.finish().unwrap();
        assert!(start.elapsed().as_millis() >= 2000);
    }
async fn tune_sets_expected_values_and_then_waits ( ) { let ( handles , _ ) = setup_requester_test ( None ) . await ; let mut buckets = leaky_bucket :: LeakyBuckets :: new ( ) ; let coordinator = buckets . coordinate ( ) . unwrap ( ) ; tokio :: spawn ( async move { coordinator . await . expect ( " " ) } ) ; let limiter = buckets . rate_limiter ( ) . max ( 200 ) . build ( ) . unwrap ( ) ; let scan = FeroxScan :: new ( " " , ScanType :: Directory , ScanOrder :: Initial , 1000 , OutputLevel :: Default , None , ) ; scan . set_status ( ScanStatus :: Running ) . unwrap ( ) ; scan . add_429 ( ) ; let requester = Requester { handles , seen_links : RwLock :: new ( HashSet :: < String > :: new ( ) ) , tuning_lock : Mutex :: new ( 0 ) , ferox_scan : scan . clone ( ) , target_url : " " . to_string ( ) , rate_limiter : RwLock :: new ( Some ( limiter ) ) , policy_data : PolicyData :: new ( RequesterPolicy :: AutoTune , 4 ) , } ; let start = Instant :: now ( ) ; let pb = scan . progress_bar ( ) ; pb . set_length ( 1000 ) ; pb . set_position ( 400 ) ; sleep ( Duration :: new ( 1 , 0 ) ) . await ; // used to get req/sec up to 400 assert_eq ! ( requester policy_data errors load ( Ordering Relaxed ) 0 ) ; requester . tune ( PolicyTrigger :: Status429 ) . await . unwrap ( ) ; assert_eq ! ( requester policy_data heap read ( ) unwrap ( ) original 400 ) ; assert_eq ! ( requester policy_data get_limit ( ) 200 ) ; assert_eq ! ( requester rate_limiter read ( ) await as_ref ( ) unwrap ( ) max ( ) 200 ) ; scan . finish ( ) . unwrap ( ) ; assert ! ( start elapsed ( ) as_millis ( ) 2000 ) ; }
tune should set req/sec and rate_limiter, adjust the limit and cooldown
tune should set req / sec and rate_limiter adjust the limit and cooldown