Skip to content

Commit

Permalink
chore(host): remove staled tests
Browse files Browse the repository at this point in the history
  • Loading branch information
keroro520 committed Feb 7, 2025
1 parent 10b9630 commit 12ef97e
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 316 deletions.
169 changes: 0 additions & 169 deletions host/src/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,172 +571,3 @@ pub async fn handle_proof(

Ok(proof)
}

#[cfg(test)]
mod tests {
use super::*;
use tokio::sync::mpsc;

#[tokio::test]
async fn test_handle_system_pause_happy_path() {
let (tx, rx) = mpsc::channel(100);
let mut actor = setup_actor_with_tasks(tx, rx);

let result = actor.handle_system_pause().await;
assert!(result.is_ok());
}

#[tokio::test]
async fn test_handle_system_pause_with_pending_tasks() {
let (tx, rx) = mpsc::channel(100);
let mut actor = setup_actor_with_tasks(tx, rx);

// Add some pending tasks
actor.pending_tasks.lock().await.push_back(ProofRequest {
block_number: 1,
l1_inclusion_block_number: 1,
network: "test".to_string(),
l1_network: "test".to_string(),
graffiti: B256::ZERO,
prover: Default::default(),
proof_type: Default::default(),
blob_proof_type: Default::default(),
prover_args: HashMap::new(),
});

let result = actor.handle_system_pause().await;
assert!(result.is_ok());

// Verify pending tasks were cleared
assert_eq!(actor.pending_tasks.lock().await.len(), 0);
}

#[tokio::test]
async fn test_handle_system_pause_with_running_tasks() {
let (tx, rx) = mpsc::channel(100);
let mut actor = setup_actor_with_tasks(tx, rx);

// Add some running tasks
let task_descriptor = ProofTaskDescriptor::default();
let cancellation_token = CancellationToken::new();
actor
.running_tasks
.lock()
.await
.insert(task_descriptor.clone(), cancellation_token.clone());

let result = actor.handle_system_pause().await;
assert!(result.is_ok());

// Verify running tasks were cancelled
assert!(cancellation_token.is_cancelled());

// TODO(Kero): Cancelled tasks should be removed from running_tasks
// assert_eq!(actor.running_tasks.lock().await.len(), 0);
}

#[tokio::test]
async fn test_handle_system_pause_with_aggregation_tasks() {
let (tx, rx) = mpsc::channel(100);
let mut actor = setup_actor_with_tasks(tx, rx);

// Add some aggregation tasks
let request = AggregationOnlyRequest::default();
let cancellation_token = CancellationToken::new();
actor
.aggregate_tasks
.lock()
.await
.insert(request.clone(), cancellation_token.clone());

let result = actor.handle_system_pause().await;
assert!(result.is_ok());

// Verify aggregation tasks were cancelled
assert!(cancellation_token.is_cancelled());
// TODO(Kero): Cancelled tasks should be removed from aggregate_tasks
// assert_eq!(actor.aggregate_tasks.lock().await.len(), 0);
}

#[tokio::test]
async fn test_handle_system_pause_with_failures() {
let (tx, rx) = mpsc::channel(100);
let mut actor = setup_actor_with_tasks(tx, rx);

// Add some pending tasks
{
actor.pending_tasks.lock().await.push_back(ProofRequest {
block_number: 1,
l1_inclusion_block_number: 1,
network: "test".to_string(),
l1_network: "test".to_string(),
graffiti: B256::ZERO,
prover: Default::default(),
proof_type: Default::default(),
blob_proof_type: Default::default(),
prover_args: HashMap::new(),
});
}

let good_running_task_token = {
// Add some running tasks
let task_descriptor = ProofTaskDescriptor::default();
let cancellation_token = CancellationToken::new();
actor
.running_tasks
.lock()
.await
.insert(task_descriptor.clone(), cancellation_token.clone());
cancellation_token
};

let good_aggregation_task_token = {
// Add some aggregation tasks
let request = AggregationOnlyRequest::default();
let cancellation_token = CancellationToken::new();
actor
.aggregate_tasks
.lock()
.await
.insert(request.clone(), cancellation_token.clone());
cancellation_token
};

// Setup tasks that will fail to cancel
{
let task_descriptor_should_fail_cause_not_supported_error = ProofTaskDescriptor {
proof_system: ProofType::Risc0,
..Default::default()
};
actor.running_tasks.lock().await.insert(
task_descriptor_should_fail_cause_not_supported_error.clone(),
CancellationToken::new(),
);
}

let result = actor.handle_system_pause().await;

// Verify error contains all accumulated errors
#[cfg(not(feature = "risc0"))]
assert!(
matches!(
result,
Err(HostError::Core(RaikoError::FeatureNotSupportedError(..)))
),
"Unexpected result: {result:?}",
);
assert!(good_running_task_token.is_cancelled());
assert!(good_aggregation_task_token.is_cancelled());
assert!(actor.pending_tasks.lock().await.is_empty());
}

// Helper function to setup actor with common test configuration
fn setup_actor_with_tasks(tx: Sender<Message>, rx: Receiver<Message>) -> ProofActor {
let opts = Opts {
concurrency_limit: 4,
..Default::default()
};

ProofActor::new(tx, rx, opts, SupportedChainSpecs::default())
}
}
6 changes: 5 additions & 1 deletion reqpool/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,11 @@ impl IdWrite for Pool {

impl Pool {
pub fn open(config: RedisPoolConfig) -> Result<Self, redis::RedisError> {
tracing::info!("RedisPool.open: connecting to redis: {}", config.redis_url);
if config.enable_memory_backend {
tracing::info!("RedisPool.open using memory pool");
} else {
tracing::info!("RedisPool.open using redis: {}", config.redis_url);
}

let client = Client::open(config.redis_url.clone())?;
Ok(Self { client, config })
Expand Down
74 changes: 0 additions & 74 deletions taskdb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,77 +430,3 @@ pub fn get_task_manager(opts: &TaskManagerOpts) -> TaskManagerWrapperImpl {
debug!("get task manager with options: {:?}", opts);
TaskManagerWrapperImpl::new(opts)
}

#[cfg(test)]
mod test {
use super::*;
use rand::Rng;

#[tokio::test]
async fn test_new_taskmanager() {
let opts = TaskManagerOpts {
max_db_size: 1024 * 1024,
redis_url: "redis://localhost:6379".to_string(),
redis_ttl: 3600,
};
let mut task_manager = get_task_manager(&opts);

let block_id = rand::thread_rng().gen_range(0..1000000);
assert_eq!(
task_manager
.enqueue_task(&ProofTaskDescriptor {
chain_id: 1,
block_id,
blockhash: B256::default(),
proof_system: ProofType::Native,
prover: "test".to_string(),
})
.await
.unwrap()
.0
.len(),
1
);
}

#[tokio::test]
async fn test_enqueue_twice() {
let opts = TaskManagerOpts {
max_db_size: 1024 * 1024,
redis_url: "redis://localhost:6379".to_string(),
redis_ttl: 3600,
};
let mut task_manager = get_task_manager(&opts);
let block_id = rand::thread_rng().gen_range(0..1000000);
let key = ProofTaskDescriptor {
chain_id: 1,
block_id,
blockhash: B256::default(),
proof_system: ProofType::Native,
prover: "test".to_string(),
};

assert_eq!(task_manager.enqueue_task(&key).await.unwrap().0.len(), 1);
// enqueue again
assert_eq!(task_manager.enqueue_task(&key).await.unwrap().0.len(), 1);

let status = task_manager.get_task_proving_status(&key).await.unwrap();
assert_eq!(status.0.len(), 1);

task_manager
.update_task_progress(key.clone(), TaskStatus::InvalidOrUnsupportedBlock, None)
.await
.expect("update task failed");
let status = task_manager.get_task_proving_status(&key).await.unwrap();
assert_eq!(status.0.len(), 2);

task_manager
.update_task_progress(key.clone(), TaskStatus::Registered, None)
.await
.expect("update task failed");
let status = task_manager.get_task_proving_status(&key).await.unwrap();
assert_eq!(status.0.len(), 3);
assert_eq!(status.0.first().unwrap().0, TaskStatus::Registered);
assert_eq!(status.0.last().unwrap().0, TaskStatus::Registered);
}
}
72 changes: 0 additions & 72 deletions taskdb/src/redis_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -819,75 +819,3 @@ impl TaskManager for RedisTaskManager {
.map_err(TaskManagerError::RedisError)
}
}

#[cfg(test)]
mod tests {
use alloy_primitives::B256;

use super::*;
use crate::ProofType;

#[test]
fn test_db_enqueue() {
let mut db = RedisTaskDb::new(RedisConfig {
url: "redis://localhost:6379".to_owned(),
ttl: 3600,
})
.unwrap();
let params = ProofTaskDescriptor {
chain_id: 1,
block_id: 1,
blockhash: B256::default(),
proof_system: ProofType::Native,
prover: "0x1234".to_owned(),
};
db.enqueue_task(&params).expect("enqueue task failed");
let status = db.get_task_proving_status(&params);
assert!(status.is_ok());
}

#[test]
fn test_db_enqueue_and_prune() {
let mut db = RedisTaskDb::new(RedisConfig {
url: "redis://localhost:6379".to_owned(),
ttl: 3600,
})
.unwrap();
let params = ProofTaskDescriptor {
chain_id: 1,
block_id: 1,
blockhash: B256::default(),
proof_system: ProofType::Native,
prover: "0x1234".to_owned(),
};
db.enqueue_task(&params).expect("enqueue task failed");
let status = db.get_task_proving_status(&params);
assert!(status.is_ok());

db.prune().expect("prune failed");
let status = db.get_task_proving_status(&params);
assert!(status.is_err());
}

#[test]
fn test_db_id_operatioins() {
let mut db = RedisTaskDb::new(RedisConfig {
url: "redis://localhost:6379".to_owned(),
ttl: 3600,
})
.unwrap();
db.prune_stored_ids().expect("prune ids failed");
let store_ids = db.list_stored_ids().expect("list ids failed");
assert_eq!(store_ids.len(), 0);

let params = (1, 1, B256::random(), 1);
db.store_id(params, "1-2-3-4".to_owned())
.expect("store id failed");
let store_ids = db.list_stored_ids().expect("list ids failed");
assert_eq!(store_ids.len(), 1);

db.remove_id(params).expect("remove id failed");
let store_ids = db.list_stored_ids().expect("list ids failed");
assert_eq!(store_ids.len(), 0);
}
}

0 comments on commit 12ef97e

Please sign in to comment.