From 764f86731d236a028222f1635310a7063bc59056 Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Wed, 24 Jan 2024 12:21:46 +0100 Subject: [PATCH] Add test to hit ratelimit --- tests/ratelimit.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 tests/ratelimit.rs diff --git a/tests/ratelimit.rs b/tests/ratelimit.rs new file mode 100644 index 0000000..f9498d7 --- /dev/null +++ b/tests/ratelimit.rs @@ -0,0 +1,23 @@ +use chorus::errors::ChorusError; + +mod common; + +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] +#[cfg_attr(not(target_arch = "wasm32"), tokio::test)] +async fn hit_ratelimit() { + let mut bundle = common::setup().await; + let mut _count = 0; + let guild = bundle.guild.read().unwrap().clone(); + while _count < 1000 { + _count += 1; + match guild.channels(&mut bundle.user).await { + Err(ChorusError::RateLimited { bucket: _ }) => { + return; + } + Err(_) => panic!("Hit different rate limit"), + _ => continue, + } + } + common::teardown(bundle).await; + panic!("Ratelimit never triggered"); +}