-
Notifications
You must be signed in to change notification settings - Fork 158
Track inbound payments by PaymentId
#948
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
base: main
Are you sure you want to change the base?
Changes from all commits
4431b84
8302b2c
64802f3
59e9707
d4e67d1
4ef9c03
4a62c03
da39b52
ccd8971
1d29fcc
16f33f1
bf7aadb
452c643
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -112,11 +112,29 @@ where | |
| } | ||
|
|
||
| pub(crate) async fn remove(&self, id: &SO::Id) -> Result<(), Error> { | ||
| self.remove_batch(std::slice::from_ref(id)).await?; | ||
| Ok(()) | ||
| } | ||
|
|
||
| pub(crate) async fn remove_batch(&self, ids: &[SO::Id]) -> Result<Vec<SO>, Error> { | ||
| let (removed_objects, result) = self.remove_batch_with_partial_result(ids).await; | ||
| result?; | ||
| Ok(removed_objects) | ||
| } | ||
|
|
||
| pub(crate) async fn remove_batch_with_partial_result( | ||
| &self, ids: &[SO::Id], | ||
| ) -> (Vec<SO>, Result<(), Error>) { | ||
| let _guard = self.mutation_lock.lock().await; | ||
| let should_remove = { self.objects.lock().expect("lock").contains_key(id) }; | ||
| if should_remove { | ||
| let mut removed_objects = Vec::new(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's do a |
||
| for id in ids { | ||
| let should_remove = { self.objects.lock().expect("lock").contains_key(id) }; | ||
| if !should_remove { | ||
| continue; | ||
| } | ||
|
|
||
| let store_key = id.encode_to_hex_str(); | ||
| KVStore::remove( | ||
| let remove_result = KVStore::remove( | ||
| &*self.kv_store, | ||
| &self.primary_namespace, | ||
| &self.secondary_namespace, | ||
|
|
@@ -134,10 +152,16 @@ where | |
| e | ||
| ); | ||
| Error::PersistenceFailed | ||
| })?; | ||
| self.objects.lock().expect("lock").remove(id); | ||
| }); | ||
| if let Err(e) = remove_result { | ||
| return (removed_objects, Err(e)); | ||
| } | ||
|
|
||
| if let Some(object) = self.objects.lock().expect("lock").remove(id) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we are here can we expect this to be |
||
| removed_objects.push(object); | ||
| } | ||
| } | ||
| Ok(()) | ||
| (removed_objects, Ok(())) | ||
| } | ||
|
|
||
| /// Returns the current in-memory object for `id`. | ||
|
|
@@ -422,6 +446,45 @@ mod tests { | |
| assert!(data_store.get(&new_id).is_none()); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn batch_remove_removes_persisted_objects() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can codex add coverage for the case where an |
||
| let store: Arc<DynStore> = Arc::new(DynStoreWrapper(InMemoryStore::new())); | ||
| let logger = Arc::new(TestLogger::new()); | ||
| let primary_namespace = "datastore_batch_remove_test_primary".to_string(); | ||
| let secondary_namespace = "datastore_batch_remove_test_secondary".to_string(); | ||
| let data_store: DataStore<TestObject, Arc<TestLogger>> = DataStore::new( | ||
| Vec::new(), | ||
| primary_namespace.clone(), | ||
| secondary_namespace.clone(), | ||
| Arc::clone(&store), | ||
| logger, | ||
| ); | ||
|
|
||
| let first = TestObject { id: TestObjectId { id: [1u8; 4] }, data: [23u8; 3] }; | ||
| let second = TestObject { id: TestObjectId { id: [2u8; 4] }, data: [42u8; 3] }; | ||
| let missing_id = TestObjectId { id: [3u8; 4] }; | ||
| assert_eq!(Ok(false), data_store.insert(first).await); | ||
| assert_eq!(Ok(false), data_store.insert(second).await); | ||
|
|
||
| assert_eq!( | ||
| Ok(vec![first, second]), | ||
| data_store.remove_batch(&[first.id, missing_id, second.id]).await | ||
| ); | ||
| assert_eq!(None, data_store.get(&first.id)); | ||
| assert_eq!(None, data_store.get(&second.id)); | ||
|
|
||
| for id in [first.id, second.id] { | ||
| assert!(KVStore::read( | ||
| &*store, | ||
| &primary_namespace, | ||
| &secondary_namespace, | ||
| &id.encode_to_hex_str() | ||
| ) | ||
| .await | ||
| .is_err()); | ||
| } | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn insert_does_not_mutate_memory_if_persist_fails() { | ||
| let id = TestObjectId { id: [42u8; 4] }; | ||
|
|
||
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.
remove_batchis really only used in tests at the moment, andfn removeabove, should we delete it and have justfn removeandfn remove_batch_with_partial_result?