Skip to content

Commit 11bb732

Browse files
committed
Split TestStore in TestStore and TestStoreInner
.. where the former holds a reference to the latter, allowing to use the latter in `async move` contexts more easily.
1 parent 9cf4f69 commit 11bb732

File tree

1 file changed

+37
-26
lines changed

1 file changed

+37
-26
lines changed

lightning/src/util/test_utils.rs

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -854,12 +854,47 @@ impl<Signer: sign::ecdsa::EcdsaChannelSigner> Persist<Signer> for TestPersister
854854
}
855855

856856
pub struct TestStore {
857-
persisted_bytes: Mutex<HashMap<String, HashMap<String, Vec<u8>>>>,
858-
read_only: bool,
857+
inner: Arc<TestStoreInner>,
859858
}
860859

861860
impl TestStore {
862861
pub fn new(read_only: bool) -> Self {
862+
let inner = Arc::new(TestStoreInner::new(read_only));
863+
Self { inner }
864+
}
865+
}
866+
867+
impl KVStoreSync for TestStore {
868+
fn read(
869+
&self, primary_namespace: &str, secondary_namespace: &str, key: &str,
870+
) -> io::Result<Vec<u8>> {
871+
self.inner.read_internal(primary_namespace, secondary_namespace, key)
872+
}
873+
874+
fn write(
875+
&self, primary_namespace: &str, secondary_namespace: &str, key: &str, buf: Vec<u8>,
876+
) -> io::Result<()> {
877+
self.inner.write_internal(primary_namespace, secondary_namespace, key, buf)
878+
}
879+
880+
fn remove(
881+
&self, primary_namespace: &str, secondary_namespace: &str, key: &str, lazy: bool,
882+
) -> io::Result<()> {
883+
self.inner.remove_internal(primary_namespace, secondary_namespace, key, lazy)
884+
}
885+
886+
fn list(&self, primary_namespace: &str, secondary_namespace: &str) -> io::Result<Vec<String>> {
887+
self.inner.list_internal(primary_namespace, secondary_namespace)
888+
}
889+
}
890+
891+
struct TestStoreInner {
892+
persisted_bytes: Mutex<HashMap<String, HashMap<String, Vec<u8>>>>,
893+
read_only: bool,
894+
}
895+
896+
impl TestStoreInner {
897+
fn new(read_only: bool) -> Self {
863898
let persisted_bytes = Mutex::new(new_hash_map());
864899
Self { persisted_bytes, read_only }
865900
}
@@ -950,30 +985,6 @@ impl TestStore {
950985
}
951986
}
952987

953-
impl KVStoreSync for TestStore {
954-
fn read(
955-
&self, primary_namespace: &str, secondary_namespace: &str, key: &str,
956-
) -> io::Result<Vec<u8>> {
957-
self.read_internal(primary_namespace, secondary_namespace, key)
958-
}
959-
960-
fn write(
961-
&self, primary_namespace: &str, secondary_namespace: &str, key: &str, buf: Vec<u8>,
962-
) -> io::Result<()> {
963-
self.write_internal(primary_namespace, secondary_namespace, key, buf)
964-
}
965-
966-
fn remove(
967-
&self, primary_namespace: &str, secondary_namespace: &str, key: &str, lazy: bool,
968-
) -> io::Result<()> {
969-
self.remove_internal(primary_namespace, secondary_namespace, key, lazy)
970-
}
971-
972-
fn list(&self, primary_namespace: &str, secondary_namespace: &str) -> io::Result<Vec<String>> {
973-
self.list_internal(primary_namespace, secondary_namespace)
974-
}
975-
}
976-
977988
unsafe impl Sync for TestStore {}
978989
unsafe impl Send for TestStore {}
979990

0 commit comments

Comments
 (0)