-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
680d651
commit 783a32c
Showing
10 changed files
with
60 additions
and
96 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[package] | ||
name = "utils" | ||
version = "0.1.0" | ||
edition = "2021" | ||
license = "MIT" | ||
repository = "https://github.com/analog-labs/chain-connectors" | ||
description = "utils for rosetta test." | ||
|
||
[dependencies] | ||
tokio = { workspace = true, features = ["rt-multi-thread", "macros"] } |
This file contains 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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use std::future::Future; | ||
|
||
/// Run the test in another thread while sending txs to force binance to mine new blocks | ||
/// # Panic | ||
/// Panics if the future panics | ||
pub async fn run_test<Fut: Future<Output = ()> + Send + 'static>(future: Fut) { | ||
// Guarantee that only one test is incrementing blocks at a time | ||
static LOCK: tokio::sync::Mutex<()> = tokio::sync::Mutex::const_new(()); | ||
|
||
// Run the test in another thread | ||
let test_handler = tokio::spawn(future); | ||
|
||
// Acquire Lock | ||
let guard = LOCK.lock().await; | ||
|
||
// Check if the test is finished after acquiring the lock | ||
if test_handler.is_finished() { | ||
// Release lock | ||
drop(guard); | ||
|
||
// Now is safe to panic | ||
if let Err(err) = test_handler.await { | ||
std::panic::resume_unwind(err.into_panic()); | ||
} | ||
return; | ||
} | ||
|
||
// Now is safe to panic | ||
if let Err(err) = test_handler.await { | ||
// Resume the panic on the main task | ||
std::panic::resume_unwind(err.into_panic()); | ||
} | ||
} |