Skip to content

Commit 75529dd

Browse files
goffrieConvex, Inc.
authored and
Convex, Inc.
committedApr 3, 2025·
Add an isolate test for runQuery recursion depth (#36187)
GitOrigin-RevId: e75d15acfe7344ff0f0554d0b14fdfee09047bcf
1 parent c48baf7 commit 75529dd

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed
 

‎crates/isolate/src/test_helpers.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1157,12 +1157,12 @@ impl<RT: Runtime, P: Persistence> UdfTest<RT, P> {
11571157
}
11581158
}
11591159

1160-
static DEFAULT_CONFIG: LazyLock<UdfTestConfig> = LazyLock::new(|| UdfTestConfig {
1160+
pub static DEFAULT_CONFIG: LazyLock<UdfTestConfig> = LazyLock::new(|| UdfTestConfig {
11611161
isolate_config: IsolateConfig::default(),
11621162
udf_server_version: Version::parse("1000.0.0").unwrap(),
11631163
});
11641164

1165-
static DEFAULT_MAX_ISOLATE_WORKERS: usize = 2;
1165+
pub static DEFAULT_MAX_ISOLATE_WORKERS: usize = 2;
11661166

11671167
#[derive(Clone)]
11681168
pub struct UdfTestConfig {

‎crates/isolate/src/tests/adversarial.rs

+21
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ use crate::{
5151
test_helpers::{
5252
UdfTest,
5353
UdfTestConfig,
54+
DEFAULT_CONFIG,
5455
},
5556
tests::logging::nested_function_udf_test,
5657
IsolateConfig,
@@ -951,3 +952,23 @@ async fn test_uncatchable_errors_are_uncatchable(rt: TestRuntime) -> anyhow::Res
951952
})
952953
.await
953954
}
955+
956+
#[convex_macro::test_runtime]
957+
async fn test_subfunction_depth(rt: TestRuntime) -> anyhow::Result<()> {
958+
let t = UdfTest::default_with_config(DEFAULT_CONFIG.clone(), 16, rt).await?;
959+
let error = t
960+
.query_js_error(
961+
"adversarial:recursiveSubfunction",
962+
assert_obj!("depth" => 9.0),
963+
)
964+
.await?;
965+
assert_contains(&error, "Cross component call depth limit exceeded");
966+
let result = t
967+
.query(
968+
"adversarial:recursiveSubfunction",
969+
assert_obj!("depth" => 8.0),
970+
)
971+
.await?;
972+
assert_eq!(result, ConvexValue::Float64(8.0));
973+
Ok(())
974+
}

‎npm-packages/udf-tests/convex/adversarial.ts

+15
Original file line numberDiff line numberDiff line change
@@ -391,3 +391,18 @@ export const simpleQuery = query(async ({ db }) => {
391391
export const invokeFunctionDirectly = query(async (ctx) => {
392392
await (simpleQuery as any)(ctx, {});
393393
});
394+
395+
export const recursiveSubfunction = query(
396+
async (ctx, { depth }: { depth: number }): Promise<number> => {
397+
if (depth > 0) {
398+
return (
399+
1 +
400+
(await ctx.runQuery(api.adversarial.recursiveSubfunction, {
401+
depth: depth - 1,
402+
}))
403+
);
404+
} else {
405+
return 0;
406+
}
407+
},
408+
);

0 commit comments

Comments
 (0)
Please sign in to comment.