Skip to content

Commit

Permalink
async_overview_test: generate some activity
Browse files Browse the repository at this point in the history
to make sure that more metrics are available
on the node.

In a real world cluster they will be very shortly
after a node boot but on CI we start a node
and immediately begin using it.
  • Loading branch information
michaelklishin committed Jan 18, 2025
1 parent a238bef commit 79a1d85
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
2 changes: 1 addition & 1 deletion tests/async_channel_tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use amqprs::connection::{Connection, OpenConnectionArguments};
// Copyright (C) 2023-2025 RabbitMQ Core Team ([email protected])
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -12,6 +11,7 @@ use amqprs::connection::{Connection, OpenConnectionArguments};
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use amqprs::connection::{Connection, OpenConnectionArguments};
use rabbitmq_http_client::api::Client;

mod test_helpers;
Expand Down
2 changes: 1 addition & 1 deletion tests/async_connection_tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use amqprs::connection::{Connection, OpenConnectionArguments};
// Copyright (C) 2023-2025 RabbitMQ Core Team ([email protected])
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -12,6 +11,7 @@ use amqprs::connection::{Connection, OpenConnectionArguments};
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use amqprs::connection::{Connection, OpenConnectionArguments};
use rabbitmq_http_client::api::Client;

mod test_helpers;
Expand Down
5 changes: 4 additions & 1 deletion tests/async_overview_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use rabbitmq_http_client::api::Client;

mod test_helpers;
use crate::test_helpers::{endpoint, PASSWORD, USERNAME};
use crate::test_helpers::{endpoint, generate_activity, PASSWORD, USERNAME};

#[tokio::test]
async fn test_async_overview() {
let endpoint = endpoint();
let rc = Client::new(&endpoint, USERNAME, PASSWORD);

let _ = generate_activity().await;

let result1 = rc.overview().await;
assert!(result1.is_ok(), "overview returned {:?}", result1);

Expand Down
32 changes: 29 additions & 3 deletions tests/test_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,55 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#![allow(dead_code)]

use rabbitmq_http_client::blocking_api::Client as GenericAPIClient;
use std::env;
use std::time::Duration;

use amqprs::channel::BasicPublishArguments;
use amqprs::connection::{Connection, OpenConnectionArguments};
use amqprs::BasicProperties;

pub const ENDPOINT: &str = "http://localhost:15672/api";
pub const USERNAME: &str = "guest";
pub const PASSWORD: &str = "guest";

pub type APIClient<'a> = GenericAPIClient<&'a str, &'a str, &'a str>;

pub fn endpoint() -> String {
ENDPOINT.to_owned()
}

#[allow(dead_code)]
pub fn hostname() -> String {
"localhost".to_owned()
}

#[allow(dead_code)]
pub fn await_metric_emission(ms: u64) {
std::thread::sleep(Duration::from_millis(ms));
}

#[allow(dead_code)]
pub fn 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();
assert!(conn.is_open());

let ch = conn.open_channel(None).await.unwrap();
assert!(ch.is_open());

let payload = String::from("a dummy message").into_bytes();
let args = BasicPublishArguments::new("amq.fanout", "");
// we do not use publisher confirms here because the goal is
// merely to force the node to serve some channel and connection metrics
// which would exist in any practically useful cluster
for _ in 0..1000 {
ch.basic_publish(BasicProperties::default(), payload.clone(), args.clone())
.await
.unwrap()
}
}

0 comments on commit 79a1d85

Please sign in to comment.