Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 162
Asyncify test suite and reintroduce VSS-internal runtime#670
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
tnull
merged 7 commits into
lightningdevkit:main
from
tnull:2025-10-asyncify-more-thingsOct 28, 2025
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
edff34c
Drop superfluous `cargo build` step
tnull ae98bef
Add missing error logs for `ReadFailed` cases
tnull b8cf41c
Drop `Condvar` and use `block_on` for `wait_next_event`
tnull 05dab40
Async'ify our test suite
tnull 8512c26
Add `async { ..await }` in remaining places
tnull e01ea05
Re-introduce internal runtime to `VssStore`
tnull 8cad63b
Fix and run all tests under `cfg(vss_test)`
tnull File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -9,7 +9,7 @@ use core::future::Future; | ||
| use core::task::{Poll, Waker}; | ||
| use std::collections::VecDeque; | ||
| use std::ops::Deref; | ||
| use std::sync::{Arc, Condvar, Mutex}; | ||
| use std::sync::{Arc, Mutex}; | ||
| use bitcoin::blockdata::locktime::absolute::LockTime; | ||
| use bitcoin::secp256k1::PublicKey; | ||
| @@ -287,7 +287,6 @@ where | ||
| { | ||
| queue: Arc<Mutex<VecDeque<Event>>>, | ||
| waker: Arc<Mutex<Option<Waker>>>, | ||
| notifier: Condvar, | ||
| kv_store: Arc<DynStore>, | ||
| logger: L, | ||
| } | ||
| @@ -299,8 +298,7 @@ where | ||
| pub(crate) fn new(kv_store: Arc<DynStore>, logger: L) -> Self { | ||
| let queue = Arc::new(Mutex::new(VecDeque::new())); | ||
| let waker = Arc::new(Mutex::new(None)); | ||
| let notifier = Condvar::new(); | ||
| Self { queue, waker, notifier, kv_store, logger } | ||
| Self { queue, waker, kv_store, logger } | ||
| } | ||
| pub(crate) fn add_event(&self, event: Event) -> Result<(), Error> { | ||
| @@ -310,8 +308,6 @@ where | ||
| self.persist_queue(&locked_queue)?; | ||
| } | ||
| self.notifier.notify_one(); | ||
| if let Some(waker) = self.waker.lock().unwrap().take() { | ||
| waker.wake(); | ||
| } | ||
| @@ -327,19 +323,12 @@ where | ||
| EventFuture { event_queue: Arc::clone(&self.queue), waker: Arc::clone(&self.waker) }.await | ||
| } | ||
| pub(crate) fn wait_next_event(&self) -> Event { | ||
| let locked_queue = | ||
| self.notifier.wait_while(self.queue.lock().unwrap(), |queue| queue.is_empty()).unwrap(); | ||
| locked_queue.front().unwrap().clone() | ||
| } | ||
| pub(crate) fn event_handled(&self) -> Result<(), Error> { | ||
| { | ||
| let mut locked_queue = self.queue.lock().unwrap(); | ||
| locked_queue.pop_front(); | ||
| self.persist_queue(&locked_queue)?; | ||
| } | ||
| self.notifier.notify_one(); | ||
| if let Some(waker) = self.waker.lock().unwrap().take() { | ||
| waker.wake(); | ||
| @@ -383,8 +372,7 @@ where | ||
| let read_queue: EventQueueDeserWrapper = Readable::read(reader)?; | ||
| let queue = Arc::new(Mutex::new(read_queue.0)); | ||
| let waker = Arc::new(Mutex::new(None)); | ||
| let notifier = Condvar::new(); | ||
| Ok(Self { queue, waker, notifier, kv_store, logger }) | ||
| Ok(Self { queue, waker, kv_store, logger }) | ||
| } | ||
| } | ||
| @@ -1637,7 +1625,6 @@ mod tests { | ||
| // Check we get the expected event and that it is returned until we mark it handled. | ||
| for _ in 0..5 { | ||
| assert_eq!(event_queue.wait_next_event(), expected_event); | ||
| assert_eq!(event_queue.next_event_async().await, expected_event); | ||
| assert_eq!(event_queue.next_event(), Some(expected_event.clone())); | ||
| } | ||
| @@ -1652,7 +1639,7 @@ mod tests { | ||
| .unwrap(); | ||
| let deser_event_queue = | ||
| EventQueue::read(&mut &persisted_bytes[..], (Arc::clone(&store), logger)).unwrap(); | ||
| assert_eq!(deser_event_queue.wait_next_event(), expected_event); | ||
| assert_eq!(deser_event_queue.next_event_async().await, expected_event); | ||
| event_queue.event_handled().unwrap(); | ||
| assert_eq!(event_queue.next_event(), None); | ||
| @@ -1721,32 +1708,5 @@ mod tests { | ||
| } | ||
| } | ||
| assert_eq!(event_queue.next_event(), None); | ||
| // Check we operate correctly, even when mixing and matching blocking and async API calls. | ||
| let (tx, mut rx) = tokio::sync::watch::channel(()); | ||
| let thread_queue = Arc::clone(&event_queue); | ||
| let thread_event = expected_event.clone(); | ||
| std::thread::spawn(move || { | ||
| let e = thread_queue.wait_next_event(); | ||
| assert_eq!(e, thread_event); | ||
| thread_queue.event_handled().unwrap(); | ||
| tx.send(()).unwrap(); | ||
| }); | ||
| let thread_queue = Arc::clone(&event_queue); | ||
| let thread_event = expected_event.clone(); | ||
| std::thread::spawn(move || { | ||
| // Sleep a bit before we enqueue the events everybody is waiting for. | ||
| std::thread::sleep(Duration::from_millis(20)); | ||
| thread_queue.add_event(thread_event.clone()).unwrap(); | ||
| thread_queue.add_event(thread_event.clone()).unwrap(); | ||
| }); | ||
| let e = event_queue.next_event_async().await; | ||
| assert_eq!(e, expected_event.clone()); | ||
joostjager marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| event_queue.event_handled().unwrap(); | ||
| rx.changed().await.unwrap(); | ||
| assert_eq!(event_queue.next_event(), None); | ||
| } | ||
| } | ||
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.