Skip to content

Commit

Permalink
Fix thread::sleep used in async context (#3768)
Browse files Browse the repository at this point in the history
  • Loading branch information
QuentinI authored Oct 17, 2024
1 parent 86df546 commit 6e95ec6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/fakeapi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ repository.workspace = true
toml = { workspace = true }
tide-disco = { workspace = true }
anyhow = { workspace = true }
async-compatibility-layer = { workspace = true }
hotshot-types = { path = "../types" }
vbs = { workspace = true }
serde = { workspace = true }
Expand Down
11 changes: 6 additions & 5 deletions crates/fakeapi/src/fake_solver.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use std::{
io::{self, ErrorKind},
thread, time,
time,
};

use anyhow::Result;
use async_compatibility_layer::art::async_sleep;
use async_lock::RwLock;
use futures::FutureExt;
use hotshot_example_types::auction_results_provider_types::TestAuctionResult;
Expand Down Expand Up @@ -83,7 +84,7 @@ impl FakeSolverState {
///
/// # Errors
/// Returns an error if the `should_fault` method is `Some`.
fn dump_builders(&self) -> Result<TestAuctionResult, ServerError> {
async fn dump_builders(&self) -> Result<TestAuctionResult, ServerError> {
if let Some(fault) = self.should_fault() {
match fault {
FakeSolverFaultType::InternalServerFault => {
Expand All @@ -94,7 +95,7 @@ impl FakeSolverState {
}
FakeSolverFaultType::TimeoutFault => {
// Sleep for the preconfigured 1 second timeout interval
thread::sleep(SOLVER_MAX_TIMEOUT_S);
async_sleep(SOLVER_MAX_TIMEOUT_S).await;
}
}
}
Expand Down Expand Up @@ -130,7 +131,7 @@ impl<TYPES: NodeType> FakeSolverApi<TYPES> for FakeSolverState {
&self,
_view_number: u64,
) -> Result<TestAuctionResult, ServerError> {
self.dump_builders()
self.dump_builders().await
}

/// Get the auction results with a valid signature.
Expand All @@ -139,7 +140,7 @@ impl<TYPES: NodeType> FakeSolverApi<TYPES> for FakeSolverState {
_view_number: u64,
_signature: &<TYPES::SignatureKey as SignatureKey>::PureAssembledSignatureType,
) -> Result<TestAuctionResult, ServerError> {
self.dump_builders()
self.dump_builders().await
}
}

Expand Down

0 comments on commit 6e95ec6

Please sign in to comment.