From 0694577dd7f93b5303bb80a758329f836f5d232b Mon Sep 17 00:00:00 2001 From: Simon Buchan Date: Wed, 5 May 2021 17:54:21 +1200 Subject: [PATCH] Break out tokio test, use required flavor=multi_thread. --- Cargo.lock | 1 + Cargo.toml | 5 ++++- tests/integration_test.rs | 40 ++++++++++----------------------------- tests/tokio_test.rs | 27 ++++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 31 deletions(-) create mode 100644 tests/tokio_test.rs diff --git a/Cargo.lock b/Cargo.lock index 44ea056..dc670ef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1704,6 +1704,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "83f0c8e7c0addab50b663055baf787d0af7f413a46e6e7fb9559a4e4db7137a5" dependencies = [ "autocfg", + "num_cpus", "pin-project-lite 0.2.6", "tokio-macros", ] diff --git a/Cargo.toml b/Cargo.toml index 59f388a..f0e077c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,9 @@ repository = "https://github.com/Srinivasa314/alcro" [[test]] name = "integration_test" + +[[test]] +name = "tokio_test" required-features = ["tokio"] [dependencies] @@ -38,4 +41,4 @@ mime_guess = "2.0.3" futures = "0.3.13" anyhow = "1.0.40" -tokio = { version = "1", features = ["rt", "macros", "test-util"] } +tokio = { version = "1", features = ["rt", "rt-multi-thread", "macros"] } diff --git a/tests/integration_test.rs b/tests/integration_test.rs index 3649157..8cf87ee 100644 --- a/tests/integration_test.rs +++ b/tests/integration_test.rs @@ -33,17 +33,19 @@ fn test_eval() { assert!(ui.eval("dtyfhgxnt*").is_err()); } -#[tokio::test] -async fn test_bind_async() { +#[test] +fn test_bind_async() { let ui = UIBuilder::new() - .content(Content::Html(r#" + .content(Content::Html( + r#" - "#)) + "#, + )) .custom_args(&["--headless"]) .run() .expect("Unable to launch"); @@ -54,32 +56,10 @@ async fn test_bind_async() { .spawn(move || { let result = format!("{}c", context.args()[0].as_str().expect("arg to be str")); context.complete(Ok(result.into())) - }); - }).unwrap(); + }) + .expect("failed to spawn thread"); + }) + .unwrap(); assert_eq!(ui.eval("foo('a')").unwrap(), "abcd"); } - -#[cfg(feature = "tokio")] -#[tokio::test] -async fn test_bind_tokio() { - let ui = UIBuilder::new() - .content(Content::Html(r#" - - "#)) - .custom_args(&["--headless"]) - .run() - .expect("Unable to launch"); - - ui.bind_tokio("bar", move |args| async move { - tokio::task::yield_now().await; - Ok(format!("{}c", args[0].as_str().expect("arg to be str")).into()) - }).unwrap(); - - assert_eq!(ui.eval("foo('a')").unwrap(), "abcd"); -} \ No newline at end of file diff --git a/tests/tokio_test.rs b/tests/tokio_test.rs new file mode 100644 index 0000000..758023a --- /dev/null +++ b/tests/tokio_test.rs @@ -0,0 +1,27 @@ +use alcro::{Content, UIBuilder}; + +#[tokio::test(flavor = "multi_thread")] +async fn test_bind_tokio() { + let ui = UIBuilder::new() + .content(Content::Html( + r#" + + "#, + )) + .custom_args(&["--headless"]) + .run() + .expect("Unable to launch"); + + ui.bind_tokio("bar", move |args| async move { + tokio::task::yield_now().await; + Ok(format!("{}c", args[0].as_str().expect("arg to be str")).into()) + }) + .unwrap(); + + assert_eq!(ui.eval("foo('a')").unwrap(), "abcd"); +}