Skip to content

Commit d5cc57b

Browse files
committed
Split TestSyncStore into TestSyncStore and TestSyncStoreInner
.. where the former holds the latter in an `Arc` that can be used in async/`Future` contexts more easily.
1 parent 90aabc2 commit d5cc57b

File tree

1 file changed

+39
-28
lines changed

1 file changed

+39
-28
lines changed

tests/common/mod.rs

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,14 +1190,51 @@ pub(crate) fn do_channel_full_cycle<E: ElectrumApi>(
11901190

11911191
// A `KVStore` impl for testing purposes that wraps all our `KVStore`s and asserts their synchronicity.
11921192
pub(crate) struct TestSyncStore {
1193+
inner: Arc<TestSyncStoreInner>,
1194+
}
1195+
1196+
impl TestSyncStore {
1197+
pub(crate) fn new(dest_dir: PathBuf) -> Self {
1198+
let inner = Arc::new(TestSyncStoreInner::new(dest_dir));
1199+
Self { inner }
1200+
}
1201+
}
1202+
1203+
impl KVStoreSync for TestSyncStore {
1204+
fn read(
1205+
&self, primary_namespace: &str, secondary_namespace: &str, key: &str,
1206+
) -> lightning::io::Result<Vec<u8>> {
1207+
self.inner.read_internal(primary_namespace, secondary_namespace, key)
1208+
}
1209+
1210+
fn write(
1211+
&self, primary_namespace: &str, secondary_namespace: &str, key: &str, buf: Vec<u8>,
1212+
) -> lightning::io::Result<()> {
1213+
self.inner.write_internal(primary_namespace, secondary_namespace, key, buf)
1214+
}
1215+
1216+
fn remove(
1217+
&self, primary_namespace: &str, secondary_namespace: &str, key: &str, lazy: bool,
1218+
) -> lightning::io::Result<()> {
1219+
self.inner.remove_internal(primary_namespace, secondary_namespace, key, lazy)
1220+
}
1221+
1222+
fn list(
1223+
&self, primary_namespace: &str, secondary_namespace: &str,
1224+
) -> lightning::io::Result<Vec<String>> {
1225+
self.inner.list_internal(primary_namespace, secondary_namespace)
1226+
}
1227+
}
1228+
1229+
struct TestSyncStoreInner {
11931230
serializer: RwLock<()>,
11941231
test_store: TestStore,
11951232
fs_store: FilesystemStore,
11961233
sqlite_store: SqliteStore,
11971234
}
11981235

1199-
impl TestSyncStore {
1200-
pub(crate) fn new(dest_dir: PathBuf) -> Self {
1236+
impl TestSyncStoreInner {
1237+
fn new(dest_dir: PathBuf) -> Self {
12011238
let serializer = RwLock::new(());
12021239
let mut fs_dir = dest_dir.clone();
12031240
fs_dir.push("fs_store");
@@ -1332,29 +1369,3 @@ impl TestSyncStore {
13321369
self.do_list(primary_namespace, secondary_namespace)
13331370
}
13341371
}
1335-
1336-
impl KVStoreSync for TestSyncStore {
1337-
fn read(
1338-
&self, primary_namespace: &str, secondary_namespace: &str, key: &str,
1339-
) -> lightning::io::Result<Vec<u8>> {
1340-
self.read_internal(primary_namespace, secondary_namespace, key)
1341-
}
1342-
1343-
fn write(
1344-
&self, primary_namespace: &str, secondary_namespace: &str, key: &str, buf: Vec<u8>,
1345-
) -> lightning::io::Result<()> {
1346-
self.write_internal(primary_namespace, secondary_namespace, key, buf)
1347-
}
1348-
1349-
fn remove(
1350-
&self, primary_namespace: &str, secondary_namespace: &str, key: &str, lazy: bool,
1351-
) -> lightning::io::Result<()> {
1352-
self.remove_internal(primary_namespace, secondary_namespace, key, lazy)
1353-
}
1354-
1355-
fn list(
1356-
&self, primary_namespace: &str, secondary_namespace: &str,
1357-
) -> lightning::io::Result<Vec<String>> {
1358-
self.list_internal(primary_namespace, secondary_namespace)
1359-
}
1360-
}

0 commit comments

Comments
 (0)