Skip to content

Commit

Permalink
Await for env.TEST_STATS_DELAY after generating activity
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelklishin committed Jan 18, 2025
1 parent 79a1d85 commit c867cf7
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/test_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ use std::time::Duration;
use amqprs::channel::BasicPublishArguments;
use amqprs::connection::{Connection, OpenConnectionArguments};
use amqprs::BasicProperties;
use tokio::time;

//
// Common
//

pub const ENDPOINT: &str = "http://localhost:15672/api";
pub const USERNAME: &str = "guest";
Expand All @@ -35,6 +40,10 @@ pub fn hostname() -> String {
"localhost".to_owned()
}

//
// Blocking client tests
//

pub fn await_metric_emission(ms: u64) {
std::thread::sleep(Duration::from_millis(ms));
}
Expand All @@ -44,6 +53,19 @@ pub fn await_queue_metric_emission() {
await_metric_emission(delay.parse::<u64>().unwrap());
}

//
// Async client tests
//

pub async fn async_await_metric_emission(ms: u64) {
time::sleep(Duration::from_millis(ms)).await;
}

pub async fn async_await_queue_metric_emission() {
let delay = env::var("TEST_STATS_DELAY").unwrap_or("500".to_owned());
await_metric_emission(delay.parse::<u64>().unwrap());
}

pub async fn generate_activity() {
let args = OpenConnectionArguments::new(&hostname(), 5672, USERNAME, PASSWORD);
let conn = Connection::open(&args).await.unwrap();
Expand All @@ -62,4 +84,6 @@ pub async fn generate_activity() {
.await
.unwrap()
}

async_await_queue_metric_emission().await;
}

0 comments on commit c867cf7

Please sign in to comment.