Skip to content

Commit

Permalink
test: run case serially
Browse files Browse the repository at this point in the history
  • Loading branch information
keroro520 committed Jan 7, 2025
1 parent 8dbca97 commit 941e104
Show file tree
Hide file tree
Showing 14 changed files with 81 additions and 19 deletions.
32 changes: 28 additions & 4 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ dirs = "5.0.1"
pathdiff = "0.2.1"
dotenv = "0.15.0"
backoff = "0.4.0"
test-log = "0.2.16"
serial_test = "3.2.0"

[patch.crates-io]
revm = { git = "https://github.com/taikoxyz/revm.git", branch = "v36-taiko" }
Expand Down
2 changes: 2 additions & 0 deletions host/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ assert_cmd = { workspace = true }
rstest = { workspace = true }
ethers-core = { workspace = true }
rand = { workspace = true }
test-log = { workspace = true }
serial_test = { workspace = true }

[features]
default = []
Expand Down
4 changes: 3 additions & 1 deletion host/src/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@ pub async fn handle_proof(
mod tests {
use super::*;
use alloy_primitives::ChainId;
use rand::Rng;
use tokio::sync::mpsc;

fn create_test_proof_request() -> ProofRequest {
Expand Down Expand Up @@ -729,9 +730,10 @@ mod tests {

// Helper function to setup actor with common test configuration
fn setup_actor_with_tasks(tx: Sender<Message>, _rx: Receiver<Message>) -> ProofActor {
let redis_database = rand::thread_rng().gen_range(0..10000);
let opts = Opts {
concurrency_limit: 4,
redis_url: "redis://localhost:6379".to_string(),
redis_url: format!("redis://localhost:6379/{redis_database}"),
redis_ttl: 3600,
..Default::default()
};
Expand Down
6 changes: 6 additions & 0 deletions host/src/server/api/v2/proof/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ async fn proof_handler(

let mut manager = prover_state.task_manager();
let status = manager.get_task_proving_status(&key).await?;
tracing::info!(
"/v2/proof, request: {:?}, status: {:?}",
proof_request,
status
);

match status.0.last() {
Some((latest_status, ..)) => {
match latest_status {
Expand Down
1 change: 1 addition & 0 deletions host/src/server/api/v3/proof/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ async fn proof_handler(

for (key, req) in tasks.iter() {
let status = manager.get_task_proving_status(key).await?;
tracing::info!("/v3/proof, request: {:?}, status: {:?}", req, status);

if let Some((latest_status, ..)) = status.0.last() {
match latest_status {
Expand Down
12 changes: 11 additions & 1 deletion host/tests/common/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ use tokio_util::sync::CancellationToken;
/// ```
/// let server = TestServerBuilder::default()
/// .port(8080)
/// .redis_url("redis://127.0.0.1:6379/0".to_string())
/// .build();
/// ```
#[derive(Default, Debug)]
pub struct TestServerBuilder {
port: Option<u16>,
redis_url: Option<String>,
}

impl TestServerBuilder {
Expand All @@ -24,11 +26,19 @@ impl TestServerBuilder {
self
}

pub fn redis_url(mut self, redis_url: String) -> Self {
self.redis_url = Some(redis_url);
self
}

pub fn build(self) -> TestServerHandle {
let port = self
.port
.unwrap_or(rand::thread_rng().gen_range(1024..65535));
let address = format!("127.0.0.1:{port}");
let redis_url = self
.redis_url
.unwrap_or("redis://localhost:6379/0".to_string());

// TODO
// opts.config_path
Expand All @@ -38,8 +48,8 @@ impl TestServerBuilder {
address,
log_level,

redis_url,
concurrency_limit: 16,
redis_url: "redis://localhost:6379".to_string(),
redis_ttl: 3600,
..Default::default()
};
Expand Down
9 changes: 8 additions & 1 deletion host/tests/common/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@ use crate::common::Client;
use crate::common::{TestServerBuilder, TestServerHandle};
use rand::Rng;

pub const REDIS_URL_PREFIX: &str = "redis://localhost:6379/";

// TODO: make sure redis is not used by other tests
pub async fn setup() -> (TestServerHandle, Client) {
let port = rand::thread_rng().gen_range(1024..65535);
let server = TestServerBuilder::default().port(port).build();
let redis_database = port % 15; // port is randomly generated, so it can be used as redis database
let server = TestServerBuilder::default()
.port(port)
.redis_url(format!("{REDIS_URL_PREFIX}{redis_database}"))
.build();
let client = server.get_client();

// Wait for the server to be ready
Expand Down
8 changes: 5 additions & 3 deletions host/tests/test/aggregate_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ use raiko_lib::consts::Network;
use raiko_lib::proof_type::ProofType;
use raiko_tasks::TaskStatus;

#[tokio::test]
#[serial_test::serial]
#[test_log::test(tokio::test)]
async fn test_v2_mainnet_aggregate_native() {
test_v2_mainnet_aggregate(Network::TaikoMainnet, ProofType::Native).await;
}

#[ignore]
#[serial_test::serial]
#[cfg(feature = "risc0")]
#[tokio::test]
#[test_log::test(tokio::test)]
async fn test_v2_mainnet_aggregate_risc0() {
test_v2_mainnet_aggregate(Network::TaikoMainnet, ProofType::Risc0).await;
}
Expand All @@ -23,7 +25,7 @@ async fn test_v2_mainnet_aggregate(network: Network, proof_type: ProofType) {
setup_mock_zkvm_elf();

let api_version = "v2";
let aggregate_block_count = 2;
let aggregate_block_count = 1;

let block_numbers = randomly_select_blocks(network, aggregate_block_count)
.await
Expand Down
9 changes: 6 additions & 3 deletions host/tests/test/cancel_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use raiko_lib::consts::Network;
use raiko_lib::proof_type::ProofType;
use raiko_tasks::TaskStatus;

#[tokio::test]
#[serial_test::serial]
#[test_log::test(tokio::test)]
pub async fn test_v2_mainnet_native_cancel() {
let api_version = "v2";
let network = Network::TaikoMainnet;
Expand Down Expand Up @@ -47,7 +48,8 @@ pub async fn test_v2_mainnet_native_cancel() {
assert!(matches!(status, api::v2::CancelStatus::Ok),);
}

#[tokio::test]
#[serial_test::serial]
#[test_log::test(tokio::test)]
pub async fn test_v2_mainnet_native_cancel_non_registered() {
let api_version = "v2";
let network = Network::TaikoMainnet;
Expand All @@ -70,7 +72,8 @@ pub async fn test_v2_mainnet_native_cancel_non_registered() {
);
}

#[tokio::test]
#[serial_test::serial]
#[test_log::test(tokio::test)]
pub async fn test_v2_mainnet_native_cancel_then_register() {
let api_version = "v2";
let network = Network::TaikoMainnet;
Expand Down
2 changes: 1 addition & 1 deletion host/tests/test/manual_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use std::str::FromStr;
/// RAIKO_TEST_MANUAL_PROVE_RAIKO_RPC_URL=https://rpc.raiko.xyz \
/// cargo test --test test_manual_prove -- --ignored
/// ```
#[tokio::test]
#[test_log::test(tokio::test)]
#[ignore]
pub async fn test_manual_prove() {
let enabled = std::env::var("RAIKO_TEST_MANUAL_PROVE_ENABLED").unwrap_or_default() == "false";
Expand Down
5 changes: 3 additions & 2 deletions host/tests/test/prove_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ use raiko_lib::consts::Network;
use raiko_lib::proof_type::ProofType;
use raiko_tasks::TaskStatus;

#[tokio::test]
#[serial_test::serial]
#[test_log::test(tokio::test)]
pub async fn test_v2_mainnet_native_prove() {
let api_version = "v2";
let network = Network::TaikoMainnet;
let proof_type = ProofType::Native;
let block_number = randomly_select_block(network)
.await
.expect("randomly select block failed");
println!(
tracing::info!(
"test_prove_v2_mainnet_native network: {network}, proof_type: {proof_type}, block_number: {block_number}"
);

Expand Down
4 changes: 3 additions & 1 deletion taskdb/src/mem_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ impl IdStore for InMemoryTaskManager {
impl TaskManager for InMemoryTaskManager {
#[cfg(not(test))]
fn new(_opts: &TaskManagerOpts) -> Self {
static INIT: Once = Once::new();
static INIT: std::sync::Once = std::sync::Once::new();
static mut SHARED_TASK_MANAGER: Option<Arc<Mutex<InMemoryTaskDb>>> = None;

INIT.call_once(|| {
Expand All @@ -314,13 +314,15 @@ impl TaskManager for InMemoryTaskManager {
}
});

tracing::info!("InMemoryTaskManager created not test");
InMemoryTaskManager {
db: unsafe { SHARED_TASK_MANAGER.clone().unwrap() },
}
}

#[cfg(test)]
fn new(_opts: &TaskManagerOpts) -> Self {
tracing::info!("InMemoryTaskManager created test");
InMemoryTaskManager {
db: Arc::new(Mutex::new(InMemoryTaskDb::new())),
}
Expand Down
4 changes: 2 additions & 2 deletions taskdb/src/redis_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use redis::{
Client, Commands, ErrorKind, FromRedisValue, RedisError, RedisResult, RedisWrite, ToRedisArgs,
Value,
};
use std::sync::{Arc, Once};
use std::sync::Arc;
use std::time::Duration;
use thiserror::Error;
use tokio::sync::Mutex;
Expand Down Expand Up @@ -685,7 +685,7 @@ impl IdWrite for RedisTaskManager {
impl TaskManager for RedisTaskManager {
#[cfg(not(test))]
fn new(opts: &TaskManagerOpts) -> Self {
static INIT: Once = Once::new();
static INIT: std::sync::Once = std::sync::Once::new();
static mut REDIS_DB: Option<Arc<Mutex<RedisTaskDb>>> = None;
INIT.call_once(|| {
unsafe {
Expand Down

0 comments on commit 941e104

Please sign in to comment.