feat(sdk): Make SlidingSync.pos already private

feat(sdk): Make SlidingSync.pos already private
This commit is contained in:
Ivan Enderlin
2023-02-22 17:42:30 +01:00
committed by GitHub
3 changed files with 27 additions and 17 deletions

View File

@@ -690,11 +690,13 @@ pub enum SlidingSyncState {
/// The mode by which the the [`SlidingSyncView`] is in fetching the data.
#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum SlidingSyncMode {
/// fully sync all rooms in the background, page by page of `batch_size`
/// Fully sync all rooms in the background, page by page of `batch_size`,
/// like `0..20`, `21..40`, 41..60` etc. assuming the `batch_size` is 20.
#[serde(alias = "FullSync")]
PagingFullSync,
/// fully sync all rooms in the background, with a growing window of
/// `batch_size`,
/// Fully sync all rooms in the background, with a growing window of
/// `batch_size`, like `0..20`, `0..40`, `0..60` etc. assuming the
/// `batch_size` is 20.
GrowingFullSync,
/// Only sync the specific windows defined
#[default]
@@ -764,8 +766,9 @@ pub struct SlidingSync {
/// The storage key to keep this cache at and load it from
storage_key: Option<String>,
// ------ Internal state
pub(crate) pos: Mutable<Option<String>>,
/// The `pos` marker.
pos: Mutable<Option<String>>,
delta_token: Mutable<Option<String>>,
/// The views of this sliding sync instance
@@ -1151,11 +1154,14 @@ impl SlidingSync {
match self.sync_once(&mut views).instrument(sync_span.clone()).await {
Ok(Some(updates)) => {
self.failure_count.store(0, Ordering::SeqCst);
yield Ok(updates)
},
}
Ok(None) => {
break;
}
Err(e) => {
if e.client_api_error_kind() == Some(&ErrorKind::UnknownPos) {
// session expired, let's reset
@@ -1187,6 +1193,19 @@ impl SlidingSync {
}
}
#[cfg(any(test, feature = "testing"))]
impl SlidingSync {
/// Get a copy of the `pos` value.
pub fn pos(&self) -> Option<String> {
self.pos.get_cloned()
}
/// Set a new value for `pos`.
pub fn set_pos(&self, new_pos: String) {
self.pos.set(Some(new_pos))
}
}
#[cfg(test)]
mod test {
use ruma::room_id;

View File

@@ -4,8 +4,6 @@
use matrix_sdk_base::Session;
use ruma::{api::MatrixVersion, device_id, user_id};
#[cfg(feature = "experimental-sliding-sync")]
use crate::sliding_sync::SlidingSync;
use crate::{config::RequestConfig, Client, ClientBuilder};
pub(crate) fn test_client_builder(homeserver_url: Option<String>) -> ClientBuilder {
@@ -33,9 +31,3 @@ pub(crate) async fn logged_in_client(homeserver_url: Option<String>) -> Client {
client
}
/// Force a specific pos-value to be used for the given sliding-sync instance.
#[cfg(feature = "experimental-sliding-sync")]
pub fn force_sliding_sync_pos(sliding_sync: &SlidingSync, new_pos: String) {
sliding_sync.pos.set(Some(new_pos));
}

View File

@@ -81,7 +81,6 @@ mod tests {
api::client::error::ErrorKind as RumaError,
events::room::message::RoomMessageEventContent, UInt,
},
test_utils::force_sliding_sync_pos,
SlidingSyncMode, SlidingSyncState, SlidingSyncView,
};
@@ -1042,7 +1041,7 @@ mod tests {
);
// force the pos to be invalid and thus this being reset internally
force_sliding_sync_pos(&sync_proxy, "100".to_owned());
sync_proxy.set_pos("100".to_string());
let mut error_seen = false;
for _n in 0..2 {
@@ -1249,7 +1248,7 @@ mod tests {
assert!(room_updated, "Room update has not been seen");
// force the pos to be invalid and thus this being reset internally
force_sliding_sync_pos(&sync_proxy, "100".to_owned());
sync_proxy.set_pos("100".to_owned());
let mut error_seen = false;
let mut room_updated = false;