#[macro_export]
macro_rules! timed_tokio_test {
(async fn $name:ident() $body:block) => {
#[tokio::test]
async fn $name() {
$crate::common::with_test_timeout(async move $body).await;
}
};
}
#[macro_export]
macro_rules! retry_transient {
($op:expr) => {{
let mut __attempt: u32 = 0;
loop {
match $op.await {
Ok(v) => break Ok::<_, glide::GlideError>(v),
Err(e) if __attempt < 15 && $crate::common::is_transient_cluster_error(&e) => {
__attempt += 1;
tokio::time::sleep(std::time::Duration::from_millis(50 * __attempt as u64))
.await;
}
Err(e) => break Err(e),
}
}
}};
}
#[macro_export]
macro_rules! server_or_skip {
() => {{
match $crate::common::TestServer::start() {
Some(s) => s,
None => {
eprintln!("SKIP: no valkey-server binary available");
return;
}
}
}};
}
#[macro_export]
macro_rules! cluster_or_skip {
() => {{
match $crate::common::ClusterHarness::start() {
Some(h) => h,
None => {
eprintln!("SKIP: cluster harness not feasible in this environment");
return;
}
}
}};
}
#[macro_export]
macro_rules! resp_test {
($name:ident, $c:ident, $body:block) => {
mod $name {
use super::*;
#[allow(unused_imports)]
use $crate::common;
#[tokio::test]
async fn resp2() {
let __srv = $crate::server_or_skip!();
let $c = __srv
.client_with_protocol(glide::ProtocolVersion::RESP2)
.await;
$crate::common::with_test_timeout(async { $body }).await;
}
#[tokio::test]
async fn resp3() {
let __srv = $crate::server_or_skip!();
let $c = __srv
.client_with_protocol(glide::ProtocolVersion::RESP3)
.await;
$crate::common::with_test_timeout(async { $body }).await;
}
}
};
}
#[macro_export]
macro_rules! matrix_test {
($name:ident, $c:ident, $body:block) => {
mod $name {
use super::*;
#[allow(unused_imports)]
use $crate::common;
#[tokio::test]
async fn standalone_resp2() {
let __srv = $crate::server_or_skip!();
let $c = __srv
.client_with_protocol(glide::ProtocolVersion::RESP2)
.await;
$crate::common::with_test_timeout(async { $body }).await;
}
#[tokio::test]
async fn standalone_resp3() {
let __srv = $crate::server_or_skip!();
let $c = __srv
.client_with_protocol(glide::ProtocolVersion::RESP3)
.await;
$crate::common::with_test_timeout(async { $body }).await;
}
#[tokio::test]
async fn cluster_resp2() {
let __h = match $crate::common::ClusterHarness::start() {
Some(h) => h,
None => {
eprintln!("SKIP: cluster harness not feasible in this environment");
return;
}
};
let $c = match __h
.client_with_protocol(glide::ProtocolVersion::RESP2)
.await
{
Some(c) => c,
None => {
eprintln!("SKIP: could not connect cluster client (RESP2)");
return;
}
};
$crate::common::with_test_timeout(async { $body }).await;
}
#[tokio::test]
async fn cluster_resp3() {
let __h = match $crate::common::ClusterHarness::start() {
Some(h) => h,
None => {
eprintln!("SKIP: cluster harness not feasible in this environment");
return;
}
};
let $c = match __h
.client_with_protocol(glide::ProtocolVersion::RESP3)
.await
{
Some(c) => c,
None => {
eprintln!("SKIP: could not connect cluster client (RESP3)");
return;
}
};
$crate::common::with_test_timeout(async { $body }).await;
}
}
};
}
#[macro_export]
macro_rules! skip_if_version_below {
($c:expr, $major:expr, $minor:expr, $patch:expr) => {{
if $crate::common::version_below(&$c, ($major, $minor, $patch)).await {
eprintln!("SKIP: requires server >= {}.{}.{}", $major, $minor, $patch);
return;
}
}};
}
#[macro_export]
macro_rules! skip_unless_command {
($c:expr, $cmd:expr) => {{
if !$crate::common::command_exists(&$c, $cmd).await {
eprintln!("SKIP: server does not support {}", $cmd);
return;
}
}};
}
#[macro_export]
macro_rules! assert_request_error {
($expr:expr) => {{
match $expr {
Err(glide::GlideError::Request(_)) => {}
Err(other) => panic!("expected RequestError, got {:?}", other),
Ok(v) => panic!("expected RequestError, got Ok({:?})", v),
}
}};
}