Skip to content

Commit 3707d2f

Browse files
committed
test: Make the timeout parameter in the assert_next_with_timeout macro optional
1 parent eaaa5e1 commit 3707d2f

File tree

1 file changed

+30
-2
lines changed
  • crates/matrix-sdk/src/test_utils

1 file changed

+30
-2
lines changed

crates/matrix-sdk/src/test_utils/mod.rs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,38 @@ pub async fn logged_in_client_with_server() -> (Client, wiremock::MockServer) {
102102
(client, server)
103103
}
104104

105-
/// Asserts the next item in a `Stream` or `Subscriber` can be loaded in the
106-
/// given timeout in the given timeout in milliseconds.
105+
/// Asserts that the next item in a `Stream` is received within a given timeout.
106+
///
107+
/// This macro waits for the next item from an asynchronous `Stream` or, if no
108+
/// item is received within the specified timeout, the macro panics.
109+
///
110+
/// # Parameters
111+
///
112+
/// - `$stream`: The `Stream` or `Subscriber` to poll for the next item.
113+
/// - `$timeout_ms` (optional): The timeout in milliseconds to wait for the next
114+
/// item. Defaults to 500ms if not provided.
115+
///
116+
/// # Example
117+
///
118+
/// ```rust
119+
/// use futures_util::{stream, StreamExt};
120+
/// use matrix_sdk::assert_next_with_timeout;
121+
///
122+
/// # async {
123+
/// let mut stream = stream::iter(vec![1, 2, 3]);
124+
/// let next_item = assert_next_with_timeout!(stream, 1000); // Waits up to 1000ms
125+
/// assert_eq!(next_item, 1);
126+
///
127+
/// // The timeout can be omitted, in which case it defaults to 500 ms.
128+
/// let next_item = assert_next_with_timeout!(stream); // Waits up to 500ms
129+
/// assert_eq!(next_item, 2);
130+
/// # };
131+
/// ```
107132
#[macro_export]
108133
macro_rules! assert_next_with_timeout {
134+
($stream:expr) => {
135+
$crate::assert_next_with_timeout!($stream, 500)
136+
};
109137
($stream:expr, $timeout_ms:expr) => {{
110138
// Needed for subscribers, as they won't use the StreamExt features
111139
#[allow(unused_imports)]

0 commit comments

Comments
 (0)