1#![doc = include_str!("../README.md")]
2#![doc(html_logo_url = "https://raw.githubusercontent.com/al8n/serf/main/art/logo_72x72.png")]
3#![forbid(unsafe_code)]
4#![deny(warnings, missing_docs)]
5#![allow(clippy::type_complexity)]
6#![cfg_attr(docsrs, feature(doc_cfg))]
7#![cfg_attr(docsrs, allow(unused_attributes))]
8
9pub(crate) mod broadcast;
10
11mod coalesce;
12
13pub mod coordinate;
15
16pub mod event;
18
19pub mod error;
21
22pub mod delegate;
24
25mod options;
26pub use options::*;
27
28pub mod types;
30
31#[cfg(feature = "encryption")]
33#[cfg_attr(docsrs, doc(cfg(feature = "encryption")))]
34pub mod key_manager;
35
36mod serf;
37pub use serf::*;
38
39mod snapshot;
40pub use snapshot::*;
41
42fn invalid_data_io_error<E: std::error::Error + Send + Sync + 'static>(e: E) -> std::io::Error {
43 std::io::Error::new(std::io::ErrorKind::InvalidData, e)
44}
45
46#[cfg(feature = "test")]
50#[cfg_attr(docsrs, doc(cfg(feature = "test")))]
51pub mod tests {
52 pub use memberlist_core::tests::{next_socket_addr_v4, next_socket_addr_v6, AnyError};
53 pub use paste;
54
55 pub use super::serf::base::tests::{serf::*, *};
56
57 #[cfg(any(feature = "test", test))]
59 #[cfg_attr(docsrs, doc(cfg(any(feature = "test", test))))]
60 #[macro_export]
61 macro_rules! unit_tests {
62 ($runtime:ty => $run:ident($($fn:ident), +$(,)?)) => {
63 $(
64 ::serf_core::tests::paste::paste! {
65 #[test]
66 fn [< test_ $fn >] () {
67 $run($fn::<$runtime>());
68 }
69 }
70 )*
71 };
72 }
73
74 #[cfg(any(feature = "test", test))]
76 #[cfg_attr(docsrs, doc(cfg(any(feature = "test", test))))]
77 #[macro_export]
78 macro_rules! unit_tests_with_expr {
79 ($run:ident($(
80 $(#[$outer:meta])*
81 $fn:ident( $expr:expr )
82 ), +$(,)?)) => {
83 $(
84 ::serf_core::tests::paste::paste! {
85 #[test]
86 $(#[$outer])*
87 fn [< test_ $fn >] () {
88 $run(async move {
89 $expr
90 });
91 }
92 }
93 )*
94 };
95 }
96
97 pub fn initialize_tests_tracing() {
99 use std::sync::Once;
100 static TRACE: Once = Once::new();
101 TRACE.call_once(|| {
102 let filter = std::env::var("RUSERF_TESTING_LOG")
103 .unwrap_or_else(|_| "serf_core=info,memberlist_core=debug".to_owned());
104 memberlist_core::tracing::subscriber::set_global_default(
105 tracing_subscriber::fmt::fmt()
106 .without_time()
107 .with_line_number(true)
108 .with_env_filter(filter)
109 .with_file(false)
110 .with_target(true)
111 .with_ansi(true)
112 .finish(),
113 )
114 .unwrap();
115 });
116 }
117
118 pub fn run<B, F>(block_on: B, fut: F)
120 where
121 B: FnOnce(F) -> F::Output,
122 F: std::future::Future<Output = ()>,
123 {
124 block_on(fut);
126 }
127}