Skip to content

Commit

Permalink
Break out tokio test, use required flavor=multi_thread.
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbuchan committed May 5, 2021
1 parent 6fb3a33 commit 0694577
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 31 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ repository = "https://github.com/Srinivasa314/alcro"

[[test]]
name = "integration_test"

[[test]]
name = "tokio_test"
required-features = ["tokio"]

[dependencies]
Expand Down Expand Up @@ -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"] }
40 changes: 10 additions & 30 deletions tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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#"
<script>
async function foo(x) {
const result = await bar(x + 'b');
return result + 'd';
}
</script>
"#))
"#,
))
.custom_args(&["--headless"])
.run()
.expect("Unable to launch");
Expand All @@ -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#"
<script>
async function foo(x) {
const result = await bar(x + 'b');
return result + 'd';
}
</script>
"#))
.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");
}
27 changes: 27 additions & 0 deletions tests/tokio_test.rs
Original file line number Diff line number Diff line change
@@ -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#"
<script>
async function foo(x) {
const result = await bar(x + 'b');
return result + 'd';
}
</script>
"#,
))
.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");
}

0 comments on commit 0694577

Please sign in to comment.