Skip to content

Commit c4648a0

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 5a98b7f commit c4648a0

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

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

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

0 commit comments

Comments
 (0)