use anyhow::Result;
use serde::{Deserialize, Serialize};
use std::time::Duration;
use theater::actor_executor::ActorOperation;
use theater::actor_handle::ActorHandle;
use theater::actor_runtime::{ActorRuntime, StartActorResult};
use theater::config::{HandlerConfig, ManifestConfig, MessageServerConfig};
use theater::id::TheaterId;
use theater::messages::{ActorMessage, TheaterCommand};
use theater::shutdown::ShutdownController;
use tokio::sync::{mpsc, oneshot};
use tokio::time::timeout;
fn create_test_manifest() -> ManifestConfig {
let mut config = ManifestConfig {
name: "test-actor".to_string(),
package: "test-package-path".to_string(),
..Default::default()
};
config.handlers.push(HandlerConfig::MessageServer(MessageServerConfig {
port: None, }));
config
}
#[tokio::test]
#[ignore]
async fn test_actor_lifecycle() {
let actor_id = TheaterId::generate();
let config = create_test_manifest();
let (theater_tx, mut theater_rx) = mpsc::channel(10);
let (actor_tx, actor_rx) = mpsc::channel(10);
let (op_tx, op_rx) = mpsc::channel(10);
let (shutdown_controller, shutdown_receiver) = ShutdownController::new();
let (result_tx, mut result_rx) = mpsc::channel(1);
tokio::spawn(async move {
while let Some(cmd) = theater_rx.recv().await {
match cmd {
TheaterCommand::NewEvent { actor_id, event } => {
println!("New event from actor {}: {:?}", actor_id, event);
}
_ => println!("Other theater command: {:?}", cmd),
}
}
});
}
#[tokio::test]
async fn test_actor_message_routing() {
let sender_id = TheaterId::generate();
let recipient_id = TheaterId::generate();
let (tx, mut rx) = mpsc::channel::<ActorMessage>(10);
let test_payload = b"test message payload".to_vec();
let message = ActorMessage {
sender: sender_id.clone(),
recipient: recipient_id.clone(),
payload: test_payload.clone(),
};
tx.send(message).await.unwrap();
let received = rx.recv().await.unwrap();
assert_eq!(received.sender, sender_id);
assert_eq!(received.recipient, recipient_id);
assert_eq!(received.payload, test_payload);
}