Skip to content

Commit

Permalink
test: Fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hywan committed Aug 31, 2023
1 parent 1b8cf7f commit 95e0414
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
6 changes: 2 additions & 4 deletions crates/matrix-sdk-ui/src/timeline/inner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl<P: RoomDataProvider> TimelineInner<P> {
let state = self.state.clone();
let ignore_user_list_stream = self.client.subscribe_to_ignore_user_list_changes();

let stream = stream! {
stream! {
pin_mut!(ignore_user_list_stream);

loop {
Expand All @@ -178,9 +178,7 @@ impl<P: RoomDataProvider> TimelineInner<P> {
state.lock().await.clear();
}
}
.switch();

stream
.switch()
}

pub(super) fn subscribe_batched(
Expand Down
5 changes: 1 addition & 4 deletions crates/matrix-sdk-ui/src/timeline/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,7 @@ impl TestTimeline {
}

fn subscribe(&self) -> impl Stream<Item = VectorDiff<Arc<TimelineItem>>> {
let stream = self.inner.subscribe();
// assert_eq!(items.len(), 0, "Please subscribe to TestTimeline before adding
// items to it");
stream
self.inner.subscribe()
}

async fn subscribe_events(&self) -> impl Stream<Item = VectorDiff<EventTimelineItem>> {
Expand Down
7 changes: 4 additions & 3 deletions examples/timeline/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::Result;
use clap::Parser;
use futures_util::StreamExt;
use futures_util::{pin_mut, StreamExt};
use matrix_sdk::{self, config::SyncSettings, ruma::OwnedRoomId, Client};
use matrix_sdk_ui::timeline::RoomExt;
use url::Url;
Expand Down Expand Up @@ -71,10 +71,11 @@ async fn main() -> Result<()> {
// Get the timeline stream and listen to it.
let room = client.get_room(&room_id).unwrap();
let timeline = room.timeline().await;
let (timeline_items, mut timeline_stream) = timeline.subscribe().await;
let timeline_stream = timeline.subscribe();

println!("Initial timeline items: {timeline_items:#?}");
tokio::spawn(async move {
pin_mut!(timeline_stream);

while let Some(diff) = timeline_stream.next().await {
println!("Received a timeline diff: {diff:#?}");
}
Expand Down
9 changes: 6 additions & 3 deletions testing/matrix-sdk-integration-testing/src/tests/reactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use assert_matches::assert_matches;
use assign::assign;
use eyeball_im::VectorDiff;
use futures_core::Stream;
use futures_util::{future::join_all, StreamExt};
use futures_util::{future::join_all, pin_mut, StreamExt};
use matrix_sdk::{
config::SyncSettings,
ruma::{
Expand All @@ -46,7 +46,10 @@ async fn test_toggling_reaction() -> Result<()> {
let room_id = room.room_id();
let timeline = room.timeline().await;
let reaction_key = "👍";
let (_items, mut stream) = timeline.subscribe().await;
let stream = timeline.subscribe();
pin_mut!(stream);

let _reset = assert_matches!(stream.next().await, Some(VectorDiff::Reset { values }) => values);

// Send message
timeline.send(RoomMessageEventContent::text_plain("hi!").into(), None).await;
Expand Down Expand Up @@ -90,7 +93,7 @@ async fn test_toggling_reaction() -> Result<()> {
let reaction = Annotation::new(event_id.clone(), reaction_key.into());

// Toggle reaction multiple times
for _ in 0..3 {
for _nth in 0..3 {
// Add
timeline.toggle_reaction(&reaction).await?;
assert_local_added(&mut stream, user_id, &event_id, &reaction, message_position).await;
Expand Down

0 comments on commit 95e0414

Please sign in to comment.