summaryrefslogtreecommitdiff
path: root/core/runtime.rs
diff options
context:
space:
mode:
Diffstat (limited to 'core/runtime.rs')
-rw-r--r--core/runtime.rs75
1 files changed, 40 insertions, 35 deletions
diff --git a/core/runtime.rs b/core/runtime.rs
index 1cbefb6fe..8c78be55b 100644
--- a/core/runtime.rs
+++ b/core/runtime.rs
@@ -2610,8 +2610,6 @@ pub mod tests {
use crate::modules::SymbolicModule;
use crate::ZeroCopyBuf;
use deno_ops::op;
- use futures::future::lazy;
- use std::ops::FnOnce;
use std::pin::Pin;
use std::rc::Rc;
use std::sync::atomic::AtomicUsize;
@@ -2623,13 +2621,6 @@ pub mod tests {
pub use crate::*;
}
- pub fn run_in_task<F>(f: F)
- where
- F: FnOnce(&mut Context) + 'static,
- {
- futures::executor::block_on(lazy(move |cx| f(cx)));
- }
-
#[derive(Copy, Clone)]
pub enum Mode {
Async,
@@ -2864,7 +2855,7 @@ pub mod tests {
#[tokio::test]
async fn test_poll_value() {
let mut runtime = JsRuntime::new(Default::default());
- run_in_task(move |cx| {
+ poll_fn(move |cx| {
let value_global = runtime
.execute_script_static("a.js", "Promise.resolve(1 + 2)")
.unwrap();
@@ -2903,7 +2894,8 @@ pub mod tests {
.unwrap();
let v = runtime.poll_value(&value_global, cx);
matches!(v, Poll::Ready(Err(e)) if e.to_string() == "Promise resolution is still pending but the event loop has already resolved.");
- });
+ Poll::Ready(())
+ }).await;
}
#[tokio::test]
@@ -3061,10 +3053,10 @@ pub mod tests {
assert_eq!(frame.column_number, Some(12));
}
- #[test]
- fn test_encode_decode() {
+ #[tokio::test]
+ async fn test_encode_decode() {
let (mut runtime, _dispatch_count) = setup(Mode::Async);
- run_in_task(move |cx| {
+ poll_fn(move |cx| {
runtime
.execute_script(
"encode_decode_test.js",
@@ -3075,13 +3067,15 @@ pub mod tests {
if let Poll::Ready(Err(_)) = runtime.poll_event_loop(cx, false) {
unreachable!();
}
- });
+ Poll::Ready(())
+ })
+ .await;
}
- #[test]
- fn test_serialize_deserialize() {
+ #[tokio::test]
+ async fn test_serialize_deserialize() {
let (mut runtime, _dispatch_count) = setup(Mode::Async);
- run_in_task(move |cx| {
+ poll_fn(move |cx| {
runtime
.execute_script(
"serialize_deserialize_test.js",
@@ -3091,11 +3085,13 @@ pub mod tests {
if let Poll::Ready(Err(_)) = runtime.poll_event_loop(cx, false) {
unreachable!();
}
- });
+ Poll::Ready(())
+ })
+ .await;
}
- #[test]
- fn test_error_builder() {
+ #[tokio::test]
+ async fn test_error_builder() {
#[op]
fn op_err() -> Result<(), Error> {
Err(custom_error("DOMExceptionOperationError", "abc"))
@@ -3111,7 +3107,7 @@ pub mod tests {
get_error_class_fn: Some(&get_error_class_name),
..Default::default()
});
- run_in_task(move |cx| {
+ poll_fn(move |cx| {
runtime
.execute_script_static(
"error_builder_test.js",
@@ -3121,7 +3117,9 @@ pub mod tests {
if let Poll::Ready(Err(_)) = runtime.poll_event_loop(cx, false) {
unreachable!();
}
- });
+ Poll::Ready(())
+ })
+ .await;
}
#[test]
@@ -3646,10 +3644,10 @@ main();
assert_eq!(result.unwrap_err().to_string(), expected_error);
}
- #[test]
- fn test_error_async_stack() {
+ #[tokio::test]
+ async fn test_error_async_stack() {
let mut runtime = JsRuntime::new(RuntimeOptions::default());
- run_in_task(move |cx| {
+ poll_fn(move |cx| {
runtime
.execute_script_static(
"error_async_stack.js",
@@ -3680,11 +3678,13 @@ main();
}
_ => panic!(),
};
+ Poll::Ready(())
})
+ .await;
}
- #[test]
- fn test_error_context() {
+ #[tokio::test]
+ async fn test_error_context() {
use anyhow::anyhow;
#[op]
@@ -3703,7 +3703,7 @@ main();
..Default::default()
});
- run_in_task(move |cx| {
+ poll_fn(move |cx| {
runtime
.execute_script_static(
"test_error_context_sync.js",
@@ -3746,13 +3746,14 @@ if (errMessage !== "higher-level sync error: original sync error") {
Poll::Ready(Err(err)) => panic!("{err:?}"),
_ => panic!(),
}
- })
+ Poll::Ready(())
+ }).await;
}
- #[test]
- fn test_pump_message_loop() {
+ #[tokio::test]
+ async fn test_pump_message_loop() {
let mut runtime = JsRuntime::new(RuntimeOptions::default());
- run_in_task(move |cx| {
+ poll_fn(move |cx| {
runtime
.execute_script_static(
"pump_message_loop.js",
@@ -3797,7 +3798,9 @@ assertEquals(1, notify_return_value);
r#"assertEquals(globalThis.resolved, true);"#,
)
.unwrap();
+ Poll::Ready(())
})
+ .await;
}
#[test]
@@ -4695,7 +4698,7 @@ Deno.core.opAsync("op_async_serialize_object_with_numbers_as_keys", {
..Default::default()
});
- run_in_task(move |cx| {
+ poll_fn(move |cx| {
let main_realm = runtime.global_realm();
let other_realm = runtime.create_realm().unwrap();
@@ -4747,7 +4750,9 @@ Deno.core.opAsync("op_async_serialize_object_with_numbers_as_keys", {
runtime.poll_event_loop(cx, false),
Poll::Ready(Ok(()))
));
- });
+ Poll::Ready(())
+ })
+ .await;
}
#[test]