Skip to content

Commit 81d028f

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 9dbaae7 commit 81d028f

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

11981198
// A `KVStore` impl for testing purposes that wraps all our `KVStore`s and asserts their synchronicity.
11991199
pub(crate) struct TestSyncStore {
1200+
inner: Arc<TestSyncStoreInner>,
1201+
}
1202+
1203+
impl TestSyncStore {
1204+
pub(crate) fn new(dest_dir: PathBuf) -> Self {
1205+
let inner = Arc::new(TestSyncStoreInner::new(dest_dir));
1206+
Self { inner }
1207+
}
1208+
}
1209+
1210+
impl KVStoreSync for TestSyncStore {
1211+
fn read(
1212+
&self, primary_namespace: &str, secondary_namespace: &str, key: &str,
1213+
) -> lightning::io::Result<Vec<u8>> {
1214+
self.inner.read_internal(primary_namespace, secondary_namespace, key)
1215+
}
1216+
1217+
fn write(
1218+
&self, primary_namespace: &str, secondary_namespace: &str, key: &str, buf: Vec<u8>,
1219+
) -> lightning::io::Result<()> {
1220+
self.inner.write_internal(primary_namespace, secondary_namespace, key, buf)
1221+
}
1222+
1223+
fn remove(
1224+
&self, primary_namespace: &str, secondary_namespace: &str, key: &str, lazy: bool,
1225+
) -> lightning::io::Result<()> {
1226+
self.inner.remove_internal(primary_namespace, secondary_namespace, key, lazy)
1227+
}
1228+
1229+
fn list(
1230+
&self, primary_namespace: &str, secondary_namespace: &str,
1231+
) -> lightning::io::Result<Vec<String>> {
1232+
self.inner.list_internal(primary_namespace, secondary_namespace)
1233+
}
1234+
}
1235+
1236+
struct TestSyncStoreInner {
12001237
serializer: RwLock<()>,
12011238
test_store: TestStore,
12021239
fs_store: FilesystemStore,
12031240
sqlite_store: SqliteStore,
12041241
}
12051242

1206-
impl TestSyncStore {
1207-
pub(crate) fn new(dest_dir: PathBuf) -> Self {
1243+
impl TestSyncStoreInner {
1244+
fn new(dest_dir: PathBuf) -> Self {
12081245
let serializer = RwLock::new(());
12091246
let mut fs_dir = dest_dir.clone();
12101247
fs_dir.push("fs_store");
@@ -1339,29 +1376,3 @@ impl TestSyncStore {
13391376
self.do_list(primary_namespace, secondary_namespace)
13401377
}
13411378
}
1342-
1343-
impl KVStoreSync for TestSyncStore {
1344-
fn read(
1345-
&self, primary_namespace: &str, secondary_namespace: &str, key: &str,
1346-
) -> lightning::io::Result<Vec<u8>> {
1347-
self.read_internal(primary_namespace, secondary_namespace, key)
1348-
}
1349-
1350-
fn write(
1351-
&self, primary_namespace: &str, secondary_namespace: &str, key: &str, buf: Vec<u8>,
1352-
) -> lightning::io::Result<()> {
1353-
self.write_internal(primary_namespace, secondary_namespace, key, buf)
1354-
}
1355-
1356-
fn remove(
1357-
&self, primary_namespace: &str, secondary_namespace: &str, key: &str, lazy: bool,
1358-
) -> lightning::io::Result<()> {
1359-
self.remove_internal(primary_namespace, secondary_namespace, key, lazy)
1360-
}
1361-
1362-
fn list(
1363-
&self, primary_namespace: &str, secondary_namespace: &str,
1364-
) -> lightning::io::Result<Vec<String>> {
1365-
self.list_internal(primary_namespace, secondary_namespace)
1366-
}
1367-
}

0 commit comments

Comments
 (0)