#![doc = include_str!("../README.md")]
use std::future::Future;
use std::num::NonZeroUsize;
use ulo::BoundAddr;
use ulo_rpc::Link;
use ulo_rpc::link::ClientProbe;
pub mod cases;
mod rt;
pub use cases::deadlines::Stamped;
#[cfg(feature = "smol")]
pub use ulo_conformance_support::OnSmol;
#[cfg(feature = "tokio")]
pub use ulo_conformance_support::OnTokio;
pub use ulo_conformance_support::{Budget, Harness, PARALLEL_VAR, Slots, failures_dir, relay, report, skipped, startup_failed};
use crate::relay::Outage;
pub trait Broker: Sized + Send + Sync + 'static {
type Harness: Harness;
type Link: Link;
const PARALLEL: Option<NonZeroUsize> = None;
fn start() -> impl Future<Output = Self> + Send;
fn link(&self) -> Self::Link;
fn client_link(&self, server: &[BoundAddr]) -> Self::Link {
let _ = server;
self.link()
}
fn disrupt(&self) -> impl Future<Output = ()> + Send;
fn outage(&self) -> Option<Outage> {
None
}
fn client_connections(&self) -> impl Future<Output = Option<usize>> + Send {
async { None }
}
fn budget(&self) -> Budget {
Budget::default()
}
#[doc(hidden)]
fn probe(link: &Self::Link) -> Option<&ClientProbe> {
let _ = link;
None
}
}
#[macro_export]
macro_rules! conformance_suite {
($broker:ty $(,)?) => {
$crate::conformance_suite!($broker; not_applicable {});
};
($broker:ty; not_applicable { $($skip:ident : $why:literal),* $(,)? } $(,)?) => {
$crate::conformance_suite!(@stamper [$] $broker; $($skip : $why),*);
};
(@stamper [$d:tt] $broker:ty; $($skip:ident : $why:literal),*) => {
macro_rules! __ulo_rpc_conformance_stamp {
$(
($skip, $d($d test:tt)*) => {
#[test]
#[ignore = $why]
$d($d test)*
};
)*
($d other:ident, $d($d test:tt)*) => {
#[test]
$d($d test)*
};
}
$(const _: () = __ulo_rpc_conformance_scenarios::$skip;)*
$crate::conformance_suite!(@cases $broker;
unary_round_trip => unary::round_trip,
handler_takes_its_context => unary::context_parameter,
domain_error_envelope => errors::domain_error,
error_handler_answers_its_own_value => errors::substituted,
unencodable_reply_is_internal => errors::unencodable_reply,
guard_refusal_is_forbidden => errors::guard_refusal,
panic_is_internal => errors::panic,
undecodable_payload_is_bad_request => errors::undecodable_payload,
headers_reach_call_headers => headers::reach_call_headers,
event_reaches_its_handler => events::reaches_handler,
a_refused_event_is_never_redelivered => events::refused_event_is_not_redelivered,
an_event_carries_none_of_its_emitter_s_deadline => events::emitter_s_deadline_is_not_the_event_s,
an_event_emitted_in_a_cancelled_execution_is_not_sent => events::cancelled_before_the_emit_is_not_sent,
an_event_sent_before_its_emitter_is_cancelled_is_handled => events::cancelled_after_the_send_is_handled,
unhandled_pattern => misses::unhandled_pattern,
unhandled_event_is_acknowledged => misses::unhandled_event,
server_stream_in_order => streams::server_stream,
client_stream => streams::client_stream,
client_stream_in_order => streams::client_stream_in_order,
bidi_stream => streams::bidi_stream,
cancel_mid_stream => cancel::mid_stream,
a_reply_stream_its_caller_does_not_read_ends_overflow => queues::reply_overflow,
a_streamed_request_its_handler_does_not_read_ends_overflow => queues::request_overflow,
deadline_ms_fires_deadline => deadlines::deadline_ms,
client_timeout_is_timeout => deadlines::client_timeout,
a_call_s_timeout_is_the_server_s_deadline => deadlines::timeout_is_the_server_s_deadline,
a_stream_s_idle_timeout_is_per_frame => deadlines::stream_idle_timeout_is_per_frame,
a_stream_s_idle_timeout_ends_it_on_silence => deadlines::idle_timeout_ends_a_silent_stream,
a_stream_s_deadline_is_the_server_s_deadline => deadlines::stream_deadline_is_the_server_s,
a_stream_with_neither_bound_runs_past_both => deadlines::stream_with_neither_bound_runs_on,
a_stream_s_unbounded_idle_timeout_outlasts_the_client_s => deadlines::unbounded_idle_timeout_outlasts_the_client_s,
a_stream_s_default_idle_timeout_is_the_client_s => deadlines::default_idle_timeout_is_the_client_s,
a_stream_s_shorter_idle_timeout_replaces_the_client_s => deadlines::shorter_idle_timeout_replaces_the_client_s,
a_stream_s_zero_idle_timeout_is_refused_before_any_frame => deadlines::zero_idle_timeout_is_refused_before_any_frame,
a_stream_s_longest_idle_timeout_does_not_panic => deadlines::longest_idle_timeout_does_not_panic,
a_call_s_zero_timeout_is_refused_before_the_server_sees_it => deadlines::zero_call_timeout_is_refused_before_the_server_sees_it,
a_stream_s_zero_deadline_is_refused_before_the_server_sees_it => deadlines::zero_stream_deadline_is_refused_before_the_server_sees_it,
a_call_past_its_execution_s_deadline_is_refused_before_the_server_sees_it => deadlines::passed_deadline_is_refused_before_the_server_sees_it,
a_call_in_a_cancelled_execution_is_refused_before_the_server_sees_it => deadlines::cancelled_execution_s_call_is_refused_before_the_server_sees_it,
a_call_s_deadline_is_measured_once_its_connection_is_made => deadlines::measured_once_connected,
a_call_whose_connect_outlasts_its_deadline_is_refused_before_the_server_sees_it => deadlines::connect_past_the_deadline_is_refused_before_the_server_sees_it,
a_call_s_timer_ends_with_its_bound_after_a_blocked_connect => deadlines::blocked_connect_s_timer_ends_with_its_bound,
connecting_does_not_stall_the_thread => threads::connecting_does_not_stall_the_thread [block_on_one_thread],
binary_payload => payloads::binary,
oversized_payload => payloads::oversized,
drain => drain::drain,
drain_window => drain::window,
a_call_held_past_a_spent_cap_is_answered_unavailable => drain::spent_cap,
a_call_held_past_a_spent_cap_is_answered_unavailable_on_one_thread => drain::spent_cap [block_on_one_thread],
recovery_after_disrupt => recovery::after_disrupt,
client_close => client_close::client_close,
an_event_reaches_one_instance => delivery::one_instance,
an_every_instance_event_reaches_each_instance => delivery::every_instance,
two_instances_answering_requests => delivery::requests_across_two_instances,
over_the_bound => admission::over_the_bound,
client_on_a_thread_without_a_runtime => threads::plain_thread,
cancel_follows_its_request => order::cancel_follows_its_request,
cancel_before_opened => order::cancel_before_opened,
a_late_opened_releases_the_held_cancel => order::late_opened,
a_held_cancel_is_dropped_when_its_hold_runs_out => order::hold_runs_out,
a_held_cancel_lasts_until_its_call_s_deadline => order::held_until_deadline,
);
};
(@cases $broker:ty; $($name:ident => $module:ident :: $case:ident $([$runner:ident])?),* $(,)?) => {
static __ULO_RPC_CONFORMANCE_SLOTS: $crate::Slots = $crate::Slots::new();
#[allow(dead_code, non_upper_case_globals)]
mod __ulo_rpc_conformance_scenarios {
$(pub(super) const $name: () = ();)*
}
$(
__ulo_rpc_conformance_stamp!($name, fn $name() {
let _slot = __ULO_RPC_CONFORMANCE_SLOTS.hold(<$broker as $crate::Broker>::PARALLEL);
$crate::conformance_suite!(@run $broker, $crate::cases::$module::$case::<$broker>() $(, $runner)?);
});
)*
};
(@run $broker:ty, $case:expr) => {
$crate::conformance_suite!(@run $broker, $case, block_on)
};
(@run $broker:ty, $case:expr, $runner:ident) => {
<<$broker as $crate::Broker>::Harness as $crate::Harness>::$runner($case)
};
}