async fn adjust_limit_resets_streak_counter_on_downward_movement() {
        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::default();
        scan.add_error();
        scan.add_error();

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

        requester.policy_data.set_reqs_sec(400);
        requester.policy_data.set_errors(1);

        let mut guard = requester.tuning_lock.lock().unwrap();
        *guard = 2;
        drop(guard);

        requester
            .adjust_limit(PolicyTrigger::Errors, false)
            .await
            .unwrap();

        assert_eq!(*requester.tuning_lock.lock().unwrap(), 0);
        assert_eq!(requester.policy_data.get_limit(), 100);
        assert_eq!(requester.policy_data.errors.load(Ordering::Relaxed), 2);
    }
/// adjust_limit should reset the streak counter when errors from scan are > policy and
/// decrease the scan rate
adjust_limit should reset the streak counter when errors from scan are > policy and
decrease the scan rate
adjust_limit should reset the streak counter when errors from scan are > policy and decrease the scan rate
async fn adjust_limit_resets_streak_counter_on_downward_movement() {
        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::default();
        scan.add_error();
        scan.add_error();
        let requester = Requester {
            handles,
            seen_links: RwLock::new(HashSet::<String>::new()),
            tuning_lock: Mutex::new(0),
            ferox_scan: Arc::new(scan),
            target_url: "http://localhost".to_string(),
            rate_limiter: RwLock::new(Some(limiter)),
            policy_data: PolicyData::new(RequesterPolicy::AutoBail, 7),
        };
        requester.policy_data.set_reqs_sec(400);
        requester.policy_data.set_errors(1);
        let mut guard = requester.tuning_lock.lock().unwrap();
        *guard = 2;
        drop(guard);
        requester
            .adjust_limit(PolicyTrigger::Errors, false)
            .await
            .unwrap();
        assert_eq!(*requester.tuning_lock.lock().unwrap(), 0);
        assert_eq!(requester.policy_data.get_limit(), 100);
        assert_eq!(requester.policy_data.errors.load(Ordering::Relaxed), 2);
    }
async fn adjust_limit_resets_streak_counter_on_downward_movement ( ) { 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 :: default ( ) ; scan . add_error ( ) ; scan . add_error ( ) ; let requester = Requester { handles , seen_links : RwLock :: new ( HashSet :: < String > :: new ( ) ) , tuning_lock : Mutex :: new ( 0 ) , ferox_scan : Arc :: new ( scan ) , target_url : " " . to_string ( ) , rate_limiter : RwLock :: new ( Some ( limiter ) ) , policy_data : PolicyData :: new ( RequesterPolicy :: AutoBail , 7 ) , } ; requester . policy_data . set_reqs_sec ( 400 ) ; requester . policy_data . set_errors ( 1 ) ; let mut guard = requester . tuning_lock . lock ( ) . unwrap ( ) ; * guard = 2 ; drop ( guard ) ; requester . adjust_limit ( PolicyTrigger :: Errors , false ) . await . unwrap ( ) ; assert_eq ! ( requester tuning_lock lock ( ) unwrap ( ) 0 ) ; assert_eq ! ( requester policy_data get_limit ( ) 100 ) ; assert_eq ! ( requester policy_data errors load ( Ordering Relaxed ) 2 ) ; }
adjust_limit should reset the streak counter when errors from scan are > policy and
decrease the scan rate
adjust_limit should reset the streak counter when errors from scan are > policy and decrease the scan rate