Replace futures::executor::block_on with tokio::block_in_place

This commit is contained in:
revue_2_presse
2025-02-25 20:19:14 +01:00
parent 4fc4152eac
commit 5d468d3e19
4 changed files with 110 additions and 51 deletions

View File

@@ -1,3 +1,5 @@
use scryer_prolog::MachineBuilder;
pub(crate) trait Expectable {
#[track_caller]
fn assert_eq(self, other: &[u8]);
@@ -31,3 +33,17 @@ pub(crate) fn load_module_test<T: Expectable>(file: &str, expected: T) {
let mut wam = MachineBuilder::default().build();
expected.assert_eq(wam.test_load_file(file).as_slice());
}
/// Same as `load_module_test` with tokio runtime
#[cfg(not(target_arch = "wasm32"))]
pub(crate) fn load_module_test_with_tokio_runtime<T: Expectable>(file: &str, expected: T) {
let runtime = tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
.unwrap();
runtime.block_on(async move {
let mut wam = MachineBuilder::default().build();
expected.assert_eq(wam.test_load_file(file).as_slice())
});
}

View File

@@ -1,4 +1,6 @@
use crate::helper::load_module_test;
#[cfg(not(target_arch = "wasm32"))]
use crate::helper::load_module_test_with_tokio_runtime;
use serial_test::serial;
// issue #831
@@ -43,3 +45,14 @@ fn load_context_unreachable() {
fn issue2725_dcg_without_module() {
load_module_test("tests-pl/issue2725.pl", "");
}
#[test]
#[cfg(feature = "http")]
#[cfg(not(target_arch = "wasm32"))]
#[cfg_attr(miri, ignore = "it takes too long to run")]
fn http_open_hanging() {
load_module_test_with_tokio_runtime(
"tests-pl/issue-http_open-hanging.pl",
"received response with status code:200\nreceived response with status code:200\nreceived response with status code:200\nreceived response with status code:200\nreceived response with status code:200\n"
);
}