Skip to content

Commit e6e2073

Browse files
committed
ARGH WIP WTF
1 parent 2862208 commit e6e2073

File tree

3 files changed

+65
-36
lines changed

3 files changed

+65
-36
lines changed

src/io/sqlite_store/mod.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ impl SqliteStoreInner {
519519
mod tests {
520520
use super::*;
521521
use crate::io::test_utils::{
522-
do_read_write_remove_list_persist, do_test_store, random_storage_path,
522+
do_invalid_write, do_read_write_remove_list_persist, do_test_store, random_storage_path,
523523
};
524524

525525
impl Drop for SqliteStore {
@@ -544,6 +544,19 @@ mod tests {
544544
do_read_write_remove_list_persist(&store);
545545
}
546546

547+
#[test]
548+
fn invalid_write_panics() {
549+
let mut temp_path = random_storage_path();
550+
temp_path.push("invalid_write_panics");
551+
let store = SqliteStore::new(
552+
temp_path,
553+
Some("test_db".to_string()),
554+
Some("test_table".to_string()),
555+
)
556+
.unwrap();
557+
do_invalid_write(&store);
558+
}
559+
547560
#[test]
548561
fn test_sqlite_store() {
549562
let mut temp_path = random_storage_path();

src/io/test_utils.rs

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,29 +49,24 @@ pub(crate) fn do_read_write_remove_list_persist<K: KVStoreSync + RefUnwindSafe>(
4949

5050
// Test the basic KVStore operations.
5151
kv_store.write(primary_namespace, secondary_namespace, key, data.clone()).unwrap();
52-
53-
// Test empty primary/secondary namespaces are allowed, but not empty primary namespace and non-empty
54-
// secondary primary_namespace, and not empty key.
55-
kv_store.write("", "", key, data.clone()).unwrap();
56-
let res =
57-
std::panic::catch_unwind(|| kv_store.write("", secondary_namespace, key, data.clone()));
58-
assert!(res.is_err());
59-
let res = std::panic::catch_unwind(|| {
60-
kv_store.write(primary_namespace, secondary_namespace, "", data.clone())
61-
});
62-
assert!(res.is_err());
52+
println!("WRITE");
6353

6454
let listed_keys = kv_store.list(primary_namespace, secondary_namespace).unwrap();
6555
assert_eq!(listed_keys.len(), 1);
6656
assert_eq!(listed_keys[0], key);
57+
println!("LIST");
6758

6859
let read_data = kv_store.read(primary_namespace, secondary_namespace, key).unwrap();
6960
assert_eq!(data, &*read_data);
61+
println!("READ");
7062

7163
kv_store.remove(primary_namespace, secondary_namespace, key).unwrap();
64+
println!("REMOVE");
7265

7366
let listed_keys = kv_store.list(primary_namespace, secondary_namespace).unwrap();
7467
assert_eq!(listed_keys.len(), 0);
68+
println!("LIST");
69+
7570

7671
// Ensure we have no issue operating with primary_namespace/secondary_namespace/key being KVSTORE_NAMESPACE_KEY_MAX_LEN
7772
let max_chars: String = std::iter::repeat('A').take(KVSTORE_NAMESPACE_KEY_MAX_LEN).collect();
@@ -80,6 +75,7 @@ pub(crate) fn do_read_write_remove_list_persist<K: KVStoreSync + RefUnwindSafe>(
8075
let listed_keys = kv_store.list(&max_chars, &max_chars).unwrap();
8176
assert_eq!(listed_keys.len(), 1);
8277
assert_eq!(listed_keys[0], max_chars);
78+
println!("LIST");
8379

8480
let read_data = kv_store.read(&max_chars, &max_chars, &max_chars).unwrap();
8581
assert_eq!(data, &*read_data);
@@ -90,6 +86,28 @@ pub(crate) fn do_read_write_remove_list_persist<K: KVStoreSync + RefUnwindSafe>(
9086
assert_eq!(listed_keys.len(), 0);
9187
}
9288

89+
pub(crate) fn do_invalid_write<K: KVStoreSync + RefUnwindSafe>(kv_store: &K) {
90+
let data = vec![42u8; 32];
91+
92+
let primary_namespace = "testspace";
93+
let secondary_namespace = "testsubspace";
94+
let key = "testkey";
95+
96+
// Test the basic KVStore operations.
97+
kv_store.write(primary_namespace, secondary_namespace, key, data.clone()).unwrap();
98+
99+
// Test empty primary/secondary namespaces are allowed, but not empty primary namespace and non-empty
100+
// secondary primary_namespace, and not empty key.
101+
kv_store.write("", "", key, data.clone()).unwrap();
102+
let res =
103+
std::panic::catch_unwind(|| kv_store.write("", secondary_namespace, key, data.clone()));
104+
assert!(res.is_err());
105+
let res = std::panic::catch_unwind(|| {
106+
kv_store.write(primary_namespace, secondary_namespace, "", data.clone())
107+
});
108+
assert!(res.is_err());
109+
}
110+
93111
pub(crate) fn create_persister<'a, K: KVStoreSync + Sync>(
94112
store: &'a K, chanmon_cfg: &'a TestChanMonCfg, max_pending_updates: u64,
95113
) -> TestMonitorUpdatePersister<'a, K> {

src/io/vss_store.rs

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ impl VssStore {
7171
let id = ATOMIC_ID.fetch_add(1, Ordering::SeqCst);
7272
format!("ldk-node-vss-runtime-{}", id)
7373
})
74-
.worker_threads(INTERNAL_RUNTIME_WORKERS)
75-
.max_blocking_threads(INTERNAL_RUNTIME_WORKERS)
7674
.build()
7775
.unwrap(),
7876
);
@@ -122,11 +120,7 @@ impl KVStoreSync for VssStore {
122120
let inner = Arc::clone(&self.inner);
123121
let fut =
124122
async move { inner.read_internal(primary_namespace, secondary_namespace, key).await };
125-
let spawned_fut = internal_runtime.spawn(fut);
126-
self.runtime.block_on(async move { spawned_fut.await }).map_err(|e| {
127-
let msg = format!("Failed to join read future: {}", e);
128-
Error::new(ErrorKind::Other, msg)
129-
})?
123+
tokio::task::block_in_place(move || internal_runtime.block_on(async move { fut.await }))
130124
}
131125

132126
fn write(
@@ -156,11 +150,7 @@ impl KVStoreSync for VssStore {
156150
)
157151
.await
158152
};
159-
let spawned_fut = internal_runtime.spawn(fut);
160-
self.runtime.block_on(async move { spawned_fut.await }).map_err(|e| {
161-
let msg = format!("Failed to join write future: {}", e);
162-
Error::new(ErrorKind::Other, msg)
163-
})?
153+
tokio::task::block_in_place(move || internal_runtime.block_on(async move { fut.await }))
164154
}
165155

166156
fn remove(
@@ -189,11 +179,7 @@ impl KVStoreSync for VssStore {
189179
)
190180
.await
191181
};
192-
let spawned_fut = internal_runtime.spawn(fut);
193-
self.runtime.block_on(async move { spawned_fut.await }).map_err(|e| {
194-
let msg = format!("Failed to join remove future: {}", e);
195-
Error::new(ErrorKind::Other, msg)
196-
})?
182+
tokio::task::block_in_place(move || internal_runtime.block_on(async move { fut.await }))
197183
}
198184

199185
fn list(&self, primary_namespace: &str, secondary_namespace: &str) -> io::Result<Vec<String>> {
@@ -206,11 +192,7 @@ impl KVStoreSync for VssStore {
206192
let secondary_namespace = secondary_namespace.to_string();
207193
let inner = Arc::clone(&self.inner);
208194
let fut = async move { inner.list_internal(primary_namespace, secondary_namespace).await };
209-
let spawned_fut = internal_runtime.spawn(fut);
210-
self.runtime.block_on(async move { spawned_fut.await }).map_err(|e| {
211-
let msg = format!("Failed to join list future: {}", e);
212-
Error::new(ErrorKind::Other, msg)
213-
})?
195+
tokio::task::block_in_place(move || internal_runtime.block_on(async move { fut.await }))
214196
}
215197
}
216198

@@ -584,7 +566,7 @@ mod tests {
584566
use vss_client::headers::FixedHeaders;
585567

586568
use super::*;
587-
use crate::io::test_utils::do_read_write_remove_list_persist;
569+
use crate::io::test_utils::{do_invalid_write, do_read_write_remove_list_persist};
588570
use crate::Logger;
589571

590572
#[test]
@@ -603,7 +585,23 @@ mod tests {
603585
do_read_write_remove_list_persist(&vss_store);
604586
}
605587

606-
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
588+
#[test]
589+
fn invalid_write_panics() {
590+
let logger = Arc::new(Logger::new_log_facade());
591+
let runtime = Arc::new(Runtime::new(logger).unwrap());
592+
let vss_base_url = std::env::var("TEST_VSS_BASE_URL").unwrap();
593+
let mut rng = thread_rng();
594+
let rand_store_id: String = (0..7).map(|_| rng.sample(Alphanumeric) as char).collect();
595+
let mut vss_seed = [0u8; 32];
596+
rng.fill_bytes(&mut vss_seed);
597+
let header_provider = Arc::new(FixedHeaders::new(HashMap::new()));
598+
let vss_store =
599+
VssStore::new(vss_base_url, rand_store_id, vss_seed, header_provider, runtime);
600+
601+
do_invalid_write(&vss_store);
602+
}
603+
604+
#[tokio::test(flavor = "multi_thread")]
607605
async fn vss_read_write_remove_list_persist_in_runtime_context() {
608606
let logger = Arc::new(Logger::new_log_facade());
609607
let runtime = Arc::new(Runtime::new(logger).unwrap());

0 commit comments

Comments
 (0)