-
Notifications
You must be signed in to change notification settings - Fork 273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bugfix: ensure the SessionStore is cleared when regenerating the OlmMachine #3338
Conversation
…achine This fixes #3110
@poljar I approve this code but can't review as I am a co-author |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of this looks good, but surely we can add some tests for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR!
The code looks good. How hard is it to add a test to ensure the caches are cleared as expected?
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3338 +/- ##
==========================================
+ Coverage 83.58% 83.60% +0.01%
==========================================
Files 240 240
Lines 24841 24849 +8
==========================================
+ Hits 20764 20774 +10
+ Misses 4077 4075 -2 ☔ View full report in Codecov by Sentry. |
The current test for this is https://github.com/matrix-org/complement-crypto/pull/52/files#diff-fd8835211753c17a95b8c01292df184e7a252c2544f0535baf79ea9db1d56d7cR243 which is what we used to verify the fix. We can probably write a unit test though for clear_caches? |
I am working on a couple of tests. |
Co-authored-by: Ivan Enderlin <[email protected]> Signed-off-by: Kegan Dougal <[email protected]>
Testing the I've added a test that A real test will bring up two store instances against the same backing store and check that they keep up to date with each other. I HEREBY PINKIE PROMISE TO WRITE A GENUINE REGRESSION TEST FOR #3110 OR FAIL TRYING. But that will be a later PR. |
e1c1028
to
558d133
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean this is a test, so you got me there...
Sorry but can we have a test that puts a session into the store and cache and then when we call the method we check that the cache is empty?
As we agreed, porting the complement test isn't necessary but please at least something that doesn't just check that a method gets called.
To help you out, you don't need a new interface, the field is available inside the store specific tests: diff --git a/crates/matrix-sdk-sqlite/src/crypto_store.rs b/crates/matrix-sdk-sqlite/src/crypto_store.rs
index 612165662..80a5fec40 100644
--- a/crates/matrix-sdk-sqlite/src/crypto_store.rs
+++ b/crates/matrix-sdk-sqlite/src/crypto_store.rs
@@ -1304,7 +1304,11 @@ mod tests {
#[cfg(test)]
mod encrypted_tests {
- use matrix_sdk_crypto::{cryptostore_integration_tests, cryptostore_integration_tests_time};
+ use matrix_sdk_crypto::{
+ cryptostore_integration_tests, cryptostore_integration_tests_time,
+ store::{Changes, CryptoStore as _, PendingChanges},
+ };
+ use matrix_sdk_test::async_test;
use once_cell::sync::Lazy;
use tempfile::{tempdir, TempDir};
@@ -1321,6 +1325,26 @@ mod encrypted_tests {
.expect("Can't create a passphrase protected store")
}
+ #[async_test]
+ async fn cache_cleared() {
+ let store = get_store("cache_cleaerd", None).await;
+ // Given we created a session and saved it in the store
+ let (account, session) = cryptostore_integration_tests::get_account_and_session().await;
+ let sender_key = session.sender_key.to_base64();
+
+ store
+ .save_pending_changes(PendingChanges { account: Some(account.deep_clone()) })
+ .await
+ .expect("Can't save account");
+
+ let changes = Changes { sessions: vec![session.clone()], ..Default::default() };
+ store.save_changes(changes).await.unwrap();
+
+ store.session_cache.get(&sender_key).expect("We should have a session");
+
+ // TODO: Clear the cache
+ }
+
cryptostore_integration_tests!();
cryptostore_integration_tests_time!();
} |
Thanks @poljar , working on it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find the other test a bit pointless, but ok if we manage to port the complement test, then we can remove it.
@@ -1695,6 +1697,36 @@ mod tests { | |||
client.get_room(room_id).expect("Just-created room not found!") | |||
} | |||
|
|||
#[cfg(feature = "e2e-encryption")] | |||
#[async_test] | |||
async fn test_regerating_olm_clears_store_caches() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure this test is really useful? This is using a fake crypto store impl, and just checking that a method has been called, which is better tested in the other test. How do y'all feel about removing this test instead and all the bootstrapping that it requires, which is a bit noisey to me?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agreed as much in my final review, it is a bit useful since it's the only place which checks that the method gets called.
Porting the complement crypto test is still in the pinkie promise so that might get rid of this noisy code.
E_TOO_SLOW |
This fixes #3110