Skip to content

Commit

Permalink
Add features for riker-macros
Browse files Browse the repository at this point in the history
  • Loading branch information
mankinskin committed Feb 6, 2021
1 parent feac5dc commit 267ab72
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
9 changes: 9 additions & 0 deletions riker-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
28 changes: 20 additions & 8 deletions riker-macros/tests/macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ impl Receive<String> 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::<NewActor>("act").unwrap();
Expand All @@ -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));
}
}

Expand Down Expand Up @@ -80,8 +83,8 @@ impl<A: Send + 'static, B: Send + 'static> Receive<String> for GenericActor<A, B
}
}

#[tokio::test]
async fn run_derived_generic_actor() {
#[riker_testkit::test]
fn run_derived_generic_actor() {
let sys = ActorSystem::new().unwrap();

let act = sys.actor_of::<GenericActor<(), ()>>("act").unwrap();
Expand All @@ -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));
}
}

Expand Down Expand Up @@ -131,8 +137,8 @@ impl Receive<Message<String>> 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::<GenericMsgActor>("act").unwrap();
Expand All @@ -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));
}
}

Expand Down Expand Up @@ -202,8 +211,8 @@ impl Receive<test_mod::Message> 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::<PathMsgActor>("act").unwrap();
Expand All @@ -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));
}
}

0 comments on commit 267ab72

Please sign in to comment.