runtime: Fix flaky tests
@@ -283,11 +283,14 @@ async fn ipfs_cat() {
let ipfs = Arc::new(ipfs_api::IpfsClient::default());
let hash = ipfs.add(Cursor::new("42")).await.unwrap().hash;
+ // Ipfs host functions use `block_on` which must be called from a sync context.
+ tokio::task::block_in_place(|| {
let mut module = test_module("ipfsCat", mock_data_source("wasm_test/ipfs_cat.wasm"));
let arg = module.asc_new(&hash);
let converted: AscPtr<AscString> = module.invoke_export("ipfsCatString", arg);
let data: String = module.instance().asc_get(converted);
assert_eq!(data, "42");
+ })
}
// The user_data value we use with calls to ipfs_map
@@ -331,6 +334,8 @@ async fn ipfs_map() {
let value = module.instance_mut().asc_new(&hash);
let user_data = module.instance_mut().asc_new(USER_DATA);
+ // Ipfs host functions use `block_on` which must be called from a sync context.
+ tokio::task::block_in_place(|| {
// Invoke the callback
let func = module
.instance()
@@ -339,7 +344,8 @@ async fn ipfs_map() {
.unwrap()
.get2()
.unwrap();
- let _: () = func(value.wasm_ptr(), user_data.wasm_ptr())?;
+ func(value.wasm_ptr(), user_data.wasm_ptr())
+ })?;
let mut mods = module
.take_instance()
@@ -416,10 +422,13 @@ async fn ipfs_map() {
async fn ipfs_fail() {
let mut module = test_module("ipfsFail", mock_data_source("wasm_test/ipfs_cat.wasm"));
+ // Ipfs host functions use `block_on` which must be called from a sync context.
+ tokio::task::block_in_place(|| {
let hash = module.instance_mut().asc_new("invalid hash");
assert!(module
.invoke_export::<_, AscString>("ipfsCat", hash,)
.is_null());
+ })
}
#[tokio::test]
