Skip to content

Commit 478df4a

Browse files
committed
test(sdk): Ensure EventCacheStoreLockGuard::clear_dirty is called!
This patch ensures that the `EventCacheStoreLockGuard::clear_dirty` method is correctly called.
1 parent 04fdf7f commit 478df4a

File tree

2 files changed

+27
-0
lines changed
  • crates
    • matrix-sdk-base/src/event_cache/store
    • matrix-sdk/src/event_cache/room

2 files changed

+27
-0
lines changed

crates/matrix-sdk-base/src/event_cache/store/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ impl EventCacheStoreLockGuard {
119119
pub fn clear_dirty(this: &Self) {
120120
this.cross_process_lock_guard.clear_dirty();
121121
}
122+
123+
/// Force to [`CrossProcessLockGuard::is_dirty`].
124+
pub fn is_dirty(this: &Self) -> bool {
125+
this.cross_process_lock_guard.is_dirty()
126+
}
122127
}
123128

124129
#[cfg(not(tarpaulin_include))]

crates/matrix-sdk/src/event_cache/room/mod.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,11 @@ mod private {
11081108
{
11091109
self.state.room_linked_chunk.revents().find_map(|(_position, event)| predicate(event))
11101110
}
1111+
1112+
#[cfg(test)]
1113+
pub fn is_dirty(&self) -> bool {
1114+
EventCacheStoreLockGuard::is_dirty(&self.store)
1115+
}
11111116
}
11121117

11131118
impl<'a> RoomEventCacheStateLockWriteGuard<'a> {
@@ -2072,6 +2077,11 @@ mod private {
20722077

20732078
Ok(())
20742079
}
2080+
2081+
#[cfg(test)]
2082+
pub fn is_dirty(&self) -> bool {
2083+
EventCacheStoreLockGuard::is_dirty(&self.store)
2084+
}
20752085
}
20762086

20772087
/// Load a linked chunk's full metadata, making sure the chunks are
@@ -4114,6 +4124,9 @@ mod timed_tests {
41144124
// shared access.
41154125
// See `RoomEventCacheStateLock::read` to learn more.
41164126

4127+
// The lock is no longer marked as dirty, it's been cleaned.
4128+
assert!(guard.is_dirty().not());
4129+
41174130
// The reload can be observed via the updates too.
41184131
assert_matches!(
41194132
updates_stream.recv().await.unwrap(),
@@ -4167,6 +4180,9 @@ mod timed_tests {
41674180
// Guard is kept alive, to ensure we can have multiple read guards alive with a
41684181
// shared access.
41694182

4183+
// The lock is no longer marked as dirty, it's been cleaned.
4184+
assert!(guard.is_dirty().not());
4185+
41704186
// The reload can be observed via the updates too.
41714187
assert_matches!(
41724188
updates_stream.recv().await.unwrap(),
@@ -4220,6 +4236,9 @@ mod timed_tests {
42204236

42214237
let guard = room_event_cache.inner.state.write().await.unwrap();
42224238

4239+
// The lock is no longer marked as dirty, it's been cleaned.
4240+
assert!(guard.is_dirty().not());
4241+
42234242
// The reload can be observed via the updates too.
42244243
assert_matches!(
42254244
updates_stream.recv().await.unwrap(),
@@ -4267,6 +4286,9 @@ mod timed_tests {
42674286

42684287
let guard = room_event_cache.inner.state.write().await.unwrap();
42694288

4289+
// The lock is no longer marked as dirty, it's been cleaned.
4290+
assert!(guard.is_dirty().not());
4291+
42704292
// The reload can be observed via the updates too.
42714293
assert_matches!(
42724294
updates_stream.recv().await.unwrap(),

0 commit comments

Comments
 (0)