mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-18 13:40:55 -04:00
feat(sdk): Make SlidingSync.pos already private.
So far, the `SlidingSync.pos` field was public to the crate. In order to avoid breaking the internal state of this type, its visibility is now private. However, we need to be able to change the value when testing the `SlidingSync` type itself. To achieve that, this patch removes the old `force_sliding_sync_pos` function, and implements 2 new functions: `set_pos` and `pos` directly on `SlidingSync` only when `#[cfg(any(test, feature ="testing"))]`.
This commit is contained in:
@@ -766,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
|
||||
@@ -1153,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
|
||||
@@ -1189,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;
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user