Skip to content

Commit b2d9ede

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 399f9cb commit b2d9ede

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
@@ -1189,14 +1189,51 @@ pub(crate) fn do_channel_full_cycle<E: ElectrumApi>(
11891189

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

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

0 commit comments

Comments
 (0)