Skip to content

Commit 491022a

Browse files
committed
runtime: fix test
1 parent dab5acf commit 491022a

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

runtime/wasm/src/host.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,8 @@ use web3::types::{Log, Transaction};
2828
use crate::host_exports::HostExports;
2929
use crate::mapping::{MappingContext, MappingRequest, MappingTrigger};
3030

31-
pub(crate) const TIMEOUT_ENV_VAR: &str = "GRAPH_MAPPING_HANDLER_TIMEOUT";
32-
3331
lazy_static! {
34-
pub static ref TIMEOUT: Option<Duration> = std::env::var(TIMEOUT_ENV_VAR)
32+
static ref TIMEOUT: Option<Duration> = std::env::var("GRAPH_MAPPING_HANDLER_TIMEOUT")
3533
.ok()
3634
.map(|s| u64::from_str(&s).expect("Invalid value for GRAPH_MAPPING_HANDLER_TIMEOUT"))
3735
.map(Duration::from_secs);

runtime/wasm/src/module/test.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@ fn test_valid_module_and_store(
2727
) -> (
2828
WasmInstance,
2929
Arc<impl Store + SubgraphDeploymentStore + EthereumCallCache>,
30+
) {
31+
test_valid_module_and_store_with_timeout(subgraph_id, data_source, None)
32+
}
33+
34+
fn test_valid_module_and_store_with_timeout(
35+
subgraph_id: &str,
36+
data_source: DataSource,
37+
timeout: Option<Duration>,
38+
) -> (
39+
WasmInstance,
40+
Arc<impl Store + SubgraphDeploymentStore + EthereumCallCache>,
3041
) {
3142
let store = STORE.clone();
3243
let metrics_registry = Arc::new(MockMetricsRegistry::new());
@@ -59,7 +70,7 @@ fn test_valid_module_and_store(
5970
Arc::new(ValidModule::new(data_source.mapping.runtime.as_ref()).unwrap()),
6071
mock_context(deployment_id, data_source, store.clone()),
6172
host_metrics,
62-
*crate::host::TIMEOUT,
73+
timeout,
6374
true,
6475
)
6576
.unwrap();

runtime/wasm/src/module/test/abi.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
use super::*;
2-
use std::env;
32

43
#[tokio::test(threaded_scheduler)]
54
async fn unbounded_loop() {
65
// Set handler timeout to 3 seconds.
7-
env::set_var(crate::host::TIMEOUT_ENV_VAR, "3");
8-
let module = test_module(
6+
let module = test_valid_module_and_store_with_timeout(
97
"unboundedLoop",
108
mock_data_source("wasm_test/non_terminating.wasm"),
11-
);
9+
Some(Duration::from_secs(3)),
10+
)
11+
.0;
1212
let func = module.get_func("loop").get0().unwrap();
1313
let res: Result<(), _> = func();
1414
assert!(res.unwrap_err().to_string().contains(TRAP_TIMEOUT));

0 commit comments

Comments
 (0)