diff --git a/riker-macros/Cargo.toml b/riker-macros/Cargo.toml index 6ffd84c6..de85ccc4 100644 --- a/riker-macros/Cargo.toml +++ b/riker-macros/Cargo.toml @@ -13,10 +13,19 @@ keywords = ["actors", "actor-model", "async", "cqrs", "event_sourcing"] [lib] proc-macro = true +[features] +default = [] +tokio_executor = ["tokio", "riker-testkit/tokio_executor"] + [dependencies] syn = { version ="1.0", features = ["parsing", "full", "extra-traits", "proc-macro"] } quote = "1.0" proc-macro2 = "1.0" +tokio = { version = "^1", features = ["rt-multi-thread", "macros", "time"], optional = true } [dev-dependencies] riker = { path = ".." } + +[dev-dependencies.riker-testkit] +git = "https://github.com/mankinskin/riker-testkit" +branch = "tokio_executor" diff --git a/riker-macros/tests/macro.rs b/riker-macros/tests/macro.rs index ee389f67..7e3da1b2 100644 --- a/riker-macros/tests/macro.rs +++ b/riker-macros/tests/macro.rs @@ -33,8 +33,8 @@ impl Receive for NewActor { } } -#[tokio::test] -async fn run_derived_actor() { +#[riker_testkit::test] +fn run_derived_actor() { let sys = ActorSystem::new().unwrap(); let act = sys.actor_of::("act").unwrap(); @@ -45,7 +45,10 @@ async fn run_derived_actor() { // wait until all direct children of the user root are terminated while sys.user_root().has_children() { // in order to lower cpu usage, sleep here + #[cfg(feature = "tokio_executor")] tokio::time::sleep(std::time::Duration::from_millis(50)).await; + #[cfg(not(feature = "tokio_executor"))] + std::thread::sleep(std::time::Duration::from_millis(50)); } } @@ -80,8 +83,8 @@ impl Receive for GenericActor>("act").unwrap(); @@ -92,7 +95,10 @@ async fn run_derived_generic_actor() { // wait until all direct children of the user root are terminated while sys.user_root().has_children() { // in order to lower cpu usage, sleep here + #[cfg(feature = "tokio_executor")] tokio::time::sleep(std::time::Duration::from_millis(50)).await; + #[cfg(not(feature = "tokio_executor"))] + std::thread::sleep(std::time::Duration::from_millis(50)); } } @@ -131,8 +137,8 @@ impl Receive> for GenericMsgActor { } } -#[tokio::test] -async fn run_generic_message_actor() { +#[riker_testkit::test] +fn run_generic_message_actor() { let sys = ActorSystem::new().unwrap(); let act = sys.actor_of::("act").unwrap(); @@ -145,7 +151,10 @@ async fn run_generic_message_actor() { // wait until all direct children of the user root are terminated while sys.user_root().has_children() { // in order to lower cpu usage, sleep here + #[cfg(feature = "tokio_executor")] tokio::time::sleep(std::time::Duration::from_millis(50)).await; + #[cfg(not(feature = "tokio_executor"))] + std::thread::sleep(std::time::Duration::from_millis(50)); } } @@ -202,8 +211,8 @@ impl Receive for PathMsgActor { } } -#[tokio::test] -async fn run_path_message_actor() { +#[riker_testkit::test] +fn run_path_message_actor() { let sys = ActorSystem::new().unwrap(); let act = sys.actor_of::("act").unwrap(); @@ -219,6 +228,9 @@ async fn run_path_message_actor() { // wait until all direct children of the user root are terminated while sys.user_root().has_children() { // in order to lower cpu usage, sleep here + #[cfg(feature = "tokio_executor")] tokio::time::sleep(std::time::Duration::from_millis(50)).await; + #[cfg(not(feature = "tokio_executor"))] + std::thread::sleep(std::time::Duration::from_millis(50)); } }