Skip to content

Commit a16c4f3

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 61aa04f commit a16c4f3

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
@@ -1107,6 +1107,11 @@ mod private {
11071107
{
11081108
self.state.room_linked_chunk.revents().find_map(|(_position, event)| predicate(event))
11091109
}
1110+
1111+
#[cfg(test)]
1112+
pub fn is_dirty(&self) -> bool {
1113+
EventCacheStoreLockGuard::is_dirty(&self.store)
1114+
}
11101115
}
11111116

11121117
impl<'a> RoomEventCacheStateLockWriteGuard<'a> {
@@ -2071,6 +2076,11 @@ mod private {
20712076

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

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

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

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

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

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

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

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

0 commit comments

Comments
 (0)