test(sdk): Fix tests and improve speed.

To improve the speed, we simply reduce the numbers of rooms involved in
the test.
This commit is contained in:
Ivan Enderlin
2023-03-15 17:54:39 +01:00
parent a2dcfa905f
commit c0f84bb8da

View File

@@ -67,7 +67,7 @@ impl From<&RoomListEntry> for RoomListEntryEasy {
#[cfg(test)]
mod tests {
use std::{
iter::repeat,
iter::{once, repeat},
time::{Duration, Instant},
};
@@ -558,7 +558,8 @@ mod tests {
let stream = sync_proxy.stream();
pin_mut!(stream);
// exactly one poll!
// Exactly one poll!
// Ranges are 0-10 for selective list, and 0-9 for growing list.
let room_summary =
stream.next().await.context("No room summary found, loop ended unsuccessfully")??;
@@ -567,14 +568,30 @@ mod tests {
assert_eq!(list.state(), SlidingSyncState::FullyLoaded, "list isn't live");
assert_eq!(full_list.state(), SlidingSyncState::PartiallyLoaded, "full isn't preloading");
// doing another two requests 0-20; 0-21 should bring full live, too
// Another poll!
// Ranges are 0-10 for selective list, and 0-19 for growing list.
let _room_summary =
stream.next().await.context("No room summary found, loop ended unsuccessfully")??;
let rooms_list = full_list.rooms_list::<RoomListEntryEasy>();
assert_eq!(
rooms_list,
repeat(RoomListEntryEasy::Filled)
.take(20)
.chain(once(RoomListEntryEasy::Empty))
.collect::<Vec<_>>()
);
assert_eq!(full_list.state(), SlidingSyncState::PartiallyLoaded, "full isn't preloading");
// One last poll, and we should get all rooms loaded.
let _room_summary =
stream.next().await.context("No room summary found, loop ended unsecessfully")??;
let rooms_list = full_list.rooms_list::<RoomListEntryEasy>();
assert_eq!(rooms_list, repeat(RoomListEntryEasy::Filled).take(21).collect::<Vec<_>>());
assert_eq!(full_list.state(), SlidingSyncState::FullyLoaded, "full isn't live yet");
assert_eq!(full_list.state(), SlidingSyncState::FullyLoaded, "full isn't fully loaded");
Ok(())
}
@@ -899,10 +916,10 @@ mod tests {
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn growing_sync_keeps_going() -> anyhow::Result<()> {
let (_client, sync_proxy_builder) = random_setup_with_rooms(50).await?;
let (_client, sync_proxy_builder) = random_setup_with_rooms(20).await?;
let growing_sync = SlidingSyncList::builder()
.sync_mode(SlidingSyncMode::GrowingFullSync)
.full_sync_batch_size(10u32)
.full_sync_batch_size(5u32)
.sort(vec!["by_recency".to_owned(), "by_name".to_owned()])
.name("growing")
.build()?;
@@ -913,9 +930,9 @@ mod tests {
let stream = sync_proxy.stream();
pin_mut!(stream);
// we have 50 and catch up in batches of 10. so let's get over to 20.
// we have 20 and catch up in batches of 5. so let's get over to 15.
for _n in 0..2 {
for _ in 0..=2 {
let room_summary = stream.next().await.context("sync has closed unexpectedly")?;
let _summary = room_summary?;
}
@@ -925,25 +942,20 @@ mod tests {
assert_eq!(
collection_simple,
repeat(RoomListEntryEasy::Filled)
.take(21)
.chain(repeat(RoomListEntryEasy::Empty).take(29))
.take(15)
.chain(repeat(RoomListEntryEasy::Empty).take(5))
.collect::<Vec<_>>()
);
// we have 50 and catch up in batches of 10. let's go two more, see it grow.
for _n in 0..2 {
let room_summary = stream.next().await.context("sync has closed unexpectedly")?;
let _summary = room_summary?;
}
// we have 20 and catch up in batches of 5. let's go one more, see it grows.
let room_summary = stream.next().await.context("sync has closed unexpectedly")?;
let _summary = room_summary?;
let collection_simple = list.rooms_list::<RoomListEntryEasy>();
assert_eq!(
collection_simple,
repeat(RoomListEntryEasy::Filled)
.take(41)
.chain(repeat(RoomListEntryEasy::Empty).take(9))
.collect::<Vec<_>>()
repeat(RoomListEntryEasy::Filled).take(20).collect::<Vec<_>>()
);
Ok(())
@@ -951,10 +963,10 @@ mod tests {
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn growing_sync_keeps_going_after_restart() -> anyhow::Result<()> {
let (_client, sync_proxy_builder) = random_setup_with_rooms(50).await?;
let (_client, sync_proxy_builder) = random_setup_with_rooms(20).await?;
let growing_sync = SlidingSyncList::builder()
.sync_mode(SlidingSyncMode::GrowingFullSync)
.full_sync_batch_size(10u32)
.full_sync_batch_size(5u32)
.sort(vec!["by_recency".to_owned(), "by_name".to_owned()])
.name("growing")
.build()?;
@@ -965,9 +977,9 @@ mod tests {
let stream = sync_proxy.stream();
pin_mut!(stream);
// we have 50 and catch up in batches of 10. so let's get over to 20.
// we have 20 and catch up in batches of 5. so let's get over to 15.
for _n in 0..2 {
for _ in 0..=2 {
let room_summary = stream.next().await.context("sync has closed unexpectedly")?;
let _summary = room_summary?;
}
@@ -980,19 +992,17 @@ mod tests {
} else {
acc
}),
21
15
);
// we have 50 and catch up in batches of 10. Let's make sure the restart
// continues
// we have 20 and catch up in batches of 5. Let's make sure the restart
// continues.
let stream = sync_proxy.stream();
pin_mut!(stream);
for _n in 0..2 {
let room_summary = stream.next().await.context("sync has closed unexpectedly")?;
let _summary = room_summary?;
}
let room_summary = stream.next().await.context("sync has closed unexpectedly")?;
let _summary = room_summary?;
let collection_simple = list.rooms_list::<RoomListEntryEasy>();
@@ -1002,7 +1012,7 @@ mod tests {
} else {
acc
}),
41
20
);
Ok(())
@@ -1010,10 +1020,11 @@ mod tests {
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn continue_on_reset() -> anyhow::Result<()> {
let (_client, sync_proxy_builder) = random_setup_with_rooms(30).await?;
let (_client, sync_proxy_builder) = random_setup_with_rooms(10).await?;
print!("setup took its time");
let growing_sync = SlidingSyncList::builder()
.sync_mode(SlidingSyncMode::GrowingFullSync)
.full_sync_batch_size(5u32)
.full_sync_maximum_number_of_rooms_to_fetch(100)
.sort(vec!["by_recency".to_owned(), "by_name".to_owned()])
.name("growing")
@@ -1030,9 +1041,10 @@ mod tests {
let stream = sync_proxy.stream();
pin_mut!(stream);
for _n in 0..2 {
for _ in 0..=2 {
let room_summary = stream.next().await.context("sync has closed unexpectedly")?;
let summary = room_summary?;
if summary.lists.iter().any(|s| s == "growing") {
break;
}
@@ -1046,14 +1058,14 @@ mod tests {
} else {
acc
}),
21
5
);
// force the pos to be invalid and thus this being reset internally
sync_proxy.set_pos("100".to_owned());
let mut error_seen = false;
for _n in 0..2 {
for _ in 0..2 {
let summary = match stream.next().await {
Some(Ok(e)) => e,
Some(Err(e)) => {
@@ -1068,6 +1080,7 @@ mod tests {
}
None => anyhow::bail!("Stream ended unexpectedly."),
};
// we only heard about the ones we had asked for
if summary.lists.iter().any(|s| s == "growing") {
break;
@@ -1084,7 +1097,7 @@ mod tests {
} else {
acc
}),
30
10
);
Ok(())
@@ -1092,10 +1105,11 @@ mod tests {
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn noticing_new_rooms_in_growing() -> anyhow::Result<()> {
let (client, sync_proxy_builder) = random_setup_with_rooms(30).await?;
let (client, sync_proxy_builder) = random_setup_with_rooms(20).await?;
print!("setup took its time");
let growing_sync = SlidingSyncList::builder()
.sync_mode(SlidingSyncMode::GrowingFullSync)
.full_sync_batch_size(10u32)
.full_sync_maximum_number_of_rooms_to_fetch(100)
.sort(vec!["by_recency".to_owned(), "by_name".to_owned()])
.name("growing")
@@ -1128,7 +1142,7 @@ mod tests {
} else {
acc
}),
30
20
);
// all found. let's add two more.
@@ -1142,10 +1156,10 @@ mod tests {
let summary = room_summary?;
// we only heard about the ones we had asked for
if summary.lists.iter().any(|s| s == "growing")
&& list.maximum_number_of_rooms().unwrap_or_default() == 32
&& list.maximum_number_of_rooms().unwrap_or_default() == 22
{
if seen {
// once we saw 32, we give it another loop to catch up!
// once we saw 22, we give it another loop to catch up!
break;
} else {
seen = true;
@@ -1161,7 +1175,7 @@ mod tests {
} else {
acc
}),
32
22
);
Ok(())