summaryrefslogtreecommitdiff
path: root/test_ffi/tests/integration_tests.rs
diff options
context:
space:
mode:
authorAapo Alasuutari <aapo.alasuutari@gmail.com>2022-06-28 12:23:36 +0300
committerGitHub <noreply@github.com>2022-06-28 14:53:36 +0530
commit00f4521b205bf25c79f0fa7c9a6840941342bda4 (patch)
treeb988db360143384ae216022846b518ceb262c80a /test_ffi/tests/integration_tests.rs
parente1c90963fbbf6571ae1b66971b83159681928ec3 (diff)
feat(ext/ffi): Thread safe callbacks (#14942)
Diffstat (limited to 'test_ffi/tests/integration_tests.rs')
-rw-r--r--test_ffi/tests/integration_tests.rs40
1 files changed, 38 insertions, 2 deletions
diff --git a/test_ffi/tests/integration_tests.rs b/test_ffi/tests/integration_tests.rs
index 77bcc758e..35f37aa14 100644
--- a/test_ffi/tests/integration_tests.rs
+++ b/test_ffi/tests/integration_tests.rs
@@ -77,6 +77,8 @@ fn basic() {
true\n\
Before\n\
true\n\
+ After\n\
+ true\n\
logCallback\n\
1 -1 2 -2 3 -3 4n -4n 0.5 -0.5 1 2 3 4 5 6 7 8\n\
u8: 8\n\
@@ -85,12 +87,14 @@ fn basic() {
30\n\
STORED_FUNCTION cleared\n\
STORED_FUNCTION_2 cleared\n\
+ Thread safe call counter: 0\n\
+ logCallback\n\
+ Thread safe call counter: 1\n\
+ u8: 8\n\
Static u32: 42\n\
Static i64: -1242464576485n\n\
Static ptr: true\n\
Static ptr value: 42\n\
- After\n\
- true\n\
Correct number of resources\n";
assert_eq!(stdout, expected);
assert_eq!(stderr, "");
@@ -118,3 +122,35 @@ fn symbol_types() {
assert!(output.status.success());
assert_eq!(stderr, "");
}
+
+#[test]
+fn thread_safe_callback() {
+ build();
+
+ let output = deno_cmd()
+ .arg("run")
+ .arg("--allow-ffi")
+ .arg("--allow-read")
+ .arg("--unstable")
+ .arg("--quiet")
+ .arg("tests/thread_safe_test.js")
+ .env("NO_COLOR", "1")
+ .output()
+ .unwrap();
+ let stdout = std::str::from_utf8(&output.stdout).unwrap();
+ let stderr = std::str::from_utf8(&output.stderr).unwrap();
+ if !output.status.success() {
+ println!("stdout {}", stdout);
+ println!("stderr {}", stderr);
+ }
+ println!("{:?}", output.status);
+ assert!(output.status.success());
+ let expected = "\
+ Callback on main thread\n\
+ Callback on worker thread\n\
+ Calling callback, isolate should stay asleep until callback is called\n\
+ Callback being called\n\
+ Isolate should now exit\n";
+ assert_eq!(stdout, expected);
+ assert_eq!(stderr, "");
+}