summaryrefslogtreecommitdiff
path: root/test_ffi/tests
diff options
context:
space:
mode:
Diffstat (limited to 'test_ffi/tests')
-rw-r--r--test_ffi/tests/event_loop_integration.ts18
-rw-r--r--test_ffi/tests/integration_tests.rs5
2 files changed, 19 insertions, 4 deletions
diff --git a/test_ffi/tests/event_loop_integration.ts b/test_ffi/tests/event_loop_integration.ts
index e44c66ab6..28152dabf 100644
--- a/test_ffi/tests/event_loop_integration.ts
+++ b/test_ffi/tests/event_loop_integration.ts
@@ -26,6 +26,7 @@ const dylib = Deno.dlopen(
} as const,
);
+let retry = false;
const tripleLogCallback = () => {
console.log("Sync");
Promise.resolve().then(() => {
@@ -35,10 +36,18 @@ const tripleLogCallback = () => {
setTimeout(() => {
console.log("Timeout");
callback.unref();
+
+ if (retry) {
+ // Re-ref and retry the call to make sure re-refing works.
+ console.log("RETRY THREAD SAFE");
+ retry = false;
+ callback.ref();
+ dylib.symbols.call_stored_function_thread_safe_and_log();
+ }
}, 10);
};
-const callback = new Deno.UnsafeCallback(
+const callback = Deno.UnsafeCallback.threadSafe(
{
parameters: [],
result: "void",
@@ -57,10 +66,11 @@ console.log("STORED_FUNCTION called");
// Wait to make sure synch logging and async logging
await new Promise((res) => setTimeout(res, 100));
-// Ref twice to make sure both `Promise.resolve().then()` and `setTimeout()`
-// must resolve before isolate exists.
-callback.ref();
+// Ref once to make sure both `Promise.resolve().then()` and `setTimeout()`
+// must resolve and unref before isolate exists.
+// One ref'ing has been done by `threadSafe` constructor.
callback.ref();
console.log("THREAD SAFE");
+retry = true;
dylib.symbols.call_stored_function_thread_safe_and_log();
diff --git a/test_ffi/tests/integration_tests.rs b/test_ffi/tests/integration_tests.rs
index fdfb5d895..e850a174a 100644
--- a/test_ffi/tests/integration_tests.rs
+++ b/test_ffi/tests/integration_tests.rs
@@ -225,6 +225,11 @@ fn event_loop_integration() {
Sync\n\
Async\n\
STORED_FUNCTION called\n\
+ Timeout\n\
+ RETRY THREAD SAFE\n\
+ Sync\n\
+ Async\n\
+ STORED_FUNCTION called\n\
Timeout\n";
assert_eq!(stdout, expected);
assert_eq!(stderr, "");