From fbe882615938d17bfc827f07cf51e998cd92bd31 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Thu, 1 Jun 2023 08:39:44 +0200 Subject: [PATCH] test(ui): Use `FutureExt::now_or_never` instead of `.await`. This patch uses `FutureExt::now_or_never` so that we don't wait on the future to be resolved to get a result. If we have a bug in our code and the test expects a value, the test will hang forever, which is not a desired behavior. With `now_or_never`, this situation cannot happen. --- .../tests/integration/timeline/sliding_sync.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/crates/matrix-sdk-ui/tests/integration/timeline/sliding_sync.rs b/crates/matrix-sdk-ui/tests/integration/timeline/sliding_sync.rs index d3a53ff66..360075314 100644 --- a/crates/matrix-sdk-ui/tests/integration/timeline/sliding_sync.rs +++ b/crates/matrix-sdk-ui/tests/integration/timeline/sliding_sync.rs @@ -3,7 +3,7 @@ use std::{pin::Pin, sync::Arc}; use anyhow::{Context, Result}; use assert_matches::assert_matches; use eyeball_im::{Vector, VectorDiff}; -use futures_util::{pin_mut, Stream, StreamExt}; +use futures_util::{pin_mut, FutureExt, Stream, StreamExt}; use matrix_sdk::{ SlidingSync, SlidingSyncList, SlidingSyncListBuilder, SlidingSyncMode, UpdateSummary, }; @@ -61,8 +61,8 @@ macro_rules! assert_timeline_stream { $( $accumulator )* { assert_matches!( - $stream.next().await, - Some(VectorDiff::PushBack { value }) => { + $stream.next().now_or_never(), + Some(Some(VectorDiff::PushBack { value })) => { assert_matches!(value.as_ref(), TimelineItem::Virtual(VirtualTimelineItem::DayDivider(_))); } ); @@ -81,8 +81,8 @@ macro_rules! assert_timeline_stream { $( $accumulator )* { assert_matches!( - $stream.next().await, - Some(VectorDiff::PushBack { value }) => { + $stream.next().now_or_never(), + Some(Some(VectorDiff::PushBack { value })) => { assert_matches!( value.as_ref(), TimelineItem::Event(event_timeline_item) => { @@ -106,8 +106,8 @@ macro_rules! assert_timeline_stream { $( $accumulator )* { assert_matches!( - $stream.next().await, - Some(VectorDiff::Set { index: $index, value }) => { + $stream.next().now_or_never(), + Some(Some(VectorDiff::Set { index: $index, value })) => { assert_matches!( value.as_ref(), TimelineItem::Event(event_timeline_item) => { @@ -131,8 +131,8 @@ macro_rules! assert_timeline_stream { $( $accumulator )* { assert_matches!( - $stream.next().await, - Some(VectorDiff::Remove { index: $index }) + $stream.next().now_or_never(), + Some(Some(VectorDiff::Remove { index: $index })) ); } ]