Skip to content

Commit e94ca23

Browse files
sjuddConvex, Inc.
authored andcommitted
Add explicit types to a few more isolate tests (#24768)
GitOrigin-RevId: b9a526f232be950c1cd632a98f14a7863b585ad5
1 parent 6aec0ec commit e94ca23

File tree

4 files changed

+37
-26
lines changed

4 files changed

+37
-26
lines changed

crates/isolate/src/test_helpers.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use common::{
3131
persistence::Persistence,
3232
query_journal::QueryJournal,
3333
runtime::{
34+
testing::TestRuntime,
3435
Runtime,
3536
SpawnHandle,
3637
UnixTimestamp,
@@ -960,6 +961,10 @@ pub struct UdfTestConfig {
960961
pub udf_server_version: Version,
961962
}
962963

964+
/// Rust can't seem to determine the type of the function argument in these
965+
/// tests, so we specify it explicitly.
966+
pub type UdfTestType = UdfTest<TestRuntime, TestPersistence>;
967+
963968
impl<RT: Runtime> UdfTest<RT, TestPersistence> {
964969
pub async fn run_test_with_isolate<F, Fut>(rt: RT, mut f: F) -> anyhow::Result<()>
965970
where

crates/isolate/src/tests/basic.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
use common::{
44
assert_obj,
55
document::CreationTime,
6-
testing::TestPersistence,
76
types::FieldName,
87
value::{
98
ConvexObject,
@@ -16,9 +15,10 @@ use runtime::testing::TestRuntime;
1615
use value::assert_val;
1716

1817
use super::assert_contains;
19-
use crate::test_helpers::UdfTest;
20-
21-
type UdfTestType = UdfTest<TestRuntime, TestPersistence>;
18+
use crate::test_helpers::{
19+
UdfTest,
20+
UdfTestType,
21+
};
2222

2323
#[convex_macro::test_runtime]
2424
async fn test_basic(rt: TestRuntime) -> anyhow::Result<()> {

crates/isolate/src/tests/source_maps.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
use common::assert_obj;
22
use runtime::testing::TestRuntime;
33

4-
use crate::test_helpers::UdfTest;
4+
use crate::test_helpers::{
5+
UdfTest,
6+
UdfTestType,
7+
};
58

69
const EXPECTED: &str = r#"
710
Uncaught Error: Oh bother!
@@ -11,7 +14,7 @@ Uncaught Error: Oh bother!
1114

1215
#[convex_macro::test_runtime]
1316
async fn test_source_mapping(rt: TestRuntime) -> anyhow::Result<()> {
14-
UdfTest::run_test_with_isolate2(rt, async move |t| {
17+
UdfTest::run_test_with_isolate2(rt, async move |t: UdfTestType| {
1518
let e = t
1619
.query_js_error("sourceMaps:throwsError", assert_obj!())
1720
.await?;

crates/isolate/src/tests/user_error.rs

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@ use value::{
2525
};
2626

2727
use super::assert_contains;
28-
use crate::test_helpers::UdfTest;
28+
use crate::test_helpers::{
29+
UdfTest,
30+
UdfTestType,
31+
};
2932

3033
#[convex_macro::test_runtime]
3134
async fn test_not_found(rt: TestRuntime) -> anyhow::Result<()> {
32-
UdfTest::run_test_with_isolate2(rt, async move |t| {
35+
UdfTest::run_test_with_isolate2(rt, async move |t: UdfTestType| {
3336
let err = t
3437
.query_js_error_no_validation("nonexistent", assert_obj!())
3538
.await?;
@@ -57,7 +60,7 @@ async fn test_not_found(rt: TestRuntime) -> anyhow::Result<()> {
5760

5861
#[convex_macro::test_runtime]
5962
async fn test_bad_arguments_error(rt: TestRuntime) -> anyhow::Result<()> {
60-
UdfTest::run_test_with_isolate2(rt, async move |t| {
63+
UdfTest::run_test_with_isolate2(rt, async move |t: UdfTestType| {
6164
must_let!(let Ok(ConvexValue::String(s)) = t.query("userError:badArgumentsError", assert_obj!()).await);
6265
assert!(s.contains("Invalid argument `id` for `db.get`"), "{s}");
6366
Ok(())
@@ -66,7 +69,7 @@ async fn test_bad_arguments_error(rt: TestRuntime) -> anyhow::Result<()> {
6669

6770
#[convex_macro::test_runtime]
6871
async fn test_bad_id_error(rt: TestRuntime) -> anyhow::Result<()> {
69-
UdfTest::run_test_with_isolate2(rt, async move |t| {
72+
UdfTest::run_test_with_isolate2(rt, async move |t: UdfTestType| {
7073
must_let!(let Ok(ConvexValue::String(s)) = t.query("userError:badIdError", assert_obj!()).await);
7174
// A system UDF (listById) relies on this error message being invariant.
7275
assert!(s.contains("Unable to decode ID"), "{s}");
@@ -76,7 +79,7 @@ async fn test_bad_id_error(rt: TestRuntime) -> anyhow::Result<()> {
7679

7780
#[convex_macro::test_runtime]
7881
async fn test_insertion_error(rt: TestRuntime) -> anyhow::Result<()> {
79-
UdfTest::run_test_with_isolate2(rt, async move |t| {
82+
UdfTest::run_test_with_isolate2(rt, async move |t: UdfTestType| {
8083
must_let!(let Ok(ConvexValue::String(s)) = t.mutation("userError:insertError", assert_obj!()).await);
8184
assert!(
8285
s.contains("System tables (prefixed with `_`) are read-only."),
@@ -90,7 +93,7 @@ async fn test_insertion_error(rt: TestRuntime) -> anyhow::Result<()> {
9093
// specifically. Ensure that the error is catchable in JavaScript.
9194
#[convex_macro::test_runtime]
9295
async fn test_insert_error_with_bigint(rt: TestRuntime) -> anyhow::Result<()> {
93-
UdfTest::run_test_with_isolate2(rt, async move |t| {
96+
UdfTest::run_test_with_isolate2(rt, async move |t: UdfTestType| {
9497
must_let!(let Ok(ConvexValue::String(s)) = t.mutation("userError:insertErrorWithBigint", assert_obj!()).await);
9598
assert!(
9699
s.contains("undefined is not a valid Convex value (present at path .bad"),
@@ -102,7 +105,7 @@ async fn test_insert_error_with_bigint(rt: TestRuntime) -> anyhow::Result<()> {
102105

103106
#[convex_macro::test_runtime]
104107
async fn test_patch_error(rt: TestRuntime) -> anyhow::Result<()> {
105-
UdfTest::run_test_with_isolate2(rt, async move |t| {
108+
UdfTest::run_test_with_isolate2(rt, async move |t: UdfTestType| {
106109
must_let!(let Ok(ConvexValue::String(s)) = t.mutation("userError:patchError", assert_obj!()).await);
107110
assert!(s.contains("Update on nonexistent document ID"), "{s}");
108111
Ok(())
@@ -112,7 +115,7 @@ async fn test_patch_error(rt: TestRuntime) -> anyhow::Result<()> {
112115
#[convex_macro::test_runtime]
113116
async fn test_patch_value_not_an_object(rt: TestRuntime) -> anyhow::Result<()> {
114117
// TODO: Reenable isolate2 when we implement table filter.
115-
UdfTest::run_test_with_isolate(rt, async move |t| {
118+
UdfTest::run_test_with_isolate(rt, async move |t: UdfTestType| {
116119
must_let!(let Ok(ConvexValue::String(s)) = t.mutation("userError:patchValueNotAnObject", assert_obj!()).await);
117120
assert!(
118121
s.contains("Invalid argument `value` for `db.patch`: Value must be an Object"),
@@ -124,7 +127,7 @@ async fn test_patch_value_not_an_object(rt: TestRuntime) -> anyhow::Result<()> {
124127

125128
#[convex_macro::test_runtime]
126129
async fn test_replace_error(rt: TestRuntime) -> anyhow::Result<()> {
127-
UdfTest::run_test_with_isolate2(rt, async move |t| {
130+
UdfTest::run_test_with_isolate2(rt, async move |t: UdfTestType| {
128131
must_let!(let Ok(ConvexValue::String(s)) = t.mutation("userError:replaceError", assert_obj!()).await);
129132
assert!(s.contains("Replace on nonexistent document ID"), "{s}");
130133
Ok(())
@@ -133,7 +136,7 @@ async fn test_replace_error(rt: TestRuntime) -> anyhow::Result<()> {
133136

134137
#[convex_macro::test_runtime]
135138
async fn test_delete_error(rt: TestRuntime) -> anyhow::Result<()> {
136-
UdfTest::run_test_with_isolate2(rt, async move |t| {
139+
UdfTest::run_test_with_isolate2(rt, async move |t: UdfTestType| {
137140
must_let!(let Ok(ConvexValue::String(s)) = t.mutation("userError:deleteError", assert_obj!()).await);
138141
assert!(s.contains("Delete on nonexistent document ID"), "{s}");
139142
Ok(())
@@ -143,7 +146,7 @@ async fn test_delete_error(rt: TestRuntime) -> anyhow::Result<()> {
143146
#[convex_macro::test_runtime]
144147
async fn test_nonexistent_table(rt: TestRuntime) -> anyhow::Result<()> {
145148
// TODO: Reenable isolate2 when we implement table filter.
146-
UdfTest::run_test_with_isolate(rt, async move |t| {
149+
UdfTest::run_test_with_isolate(rt, async move |t: UdfTestType| {
147150
t.create_index("boatVotes.by_boat", "boat").await?;
148151
t.backfill_indexes().await?;
149152
let mut tx = t.database.begin(Identity::system()).await?;
@@ -161,7 +164,7 @@ async fn test_nonexistent_table(rt: TestRuntime) -> anyhow::Result<()> {
161164

162165
#[convex_macro::test_runtime]
163166
async fn test_nonexistent_id(rt: TestRuntime) -> anyhow::Result<()> {
164-
UdfTest::run_test_with_isolate2(rt, async move |t| {
167+
UdfTest::run_test_with_isolate2(rt, async move |t: UdfTestType| {
165168
let mut tx = t.database.begin(Identity::system()).await?;
166169
let table_number = 8000.try_into()?;
167170
let table_name: TableName = "_my_system_table".parse()?;
@@ -221,7 +224,7 @@ async fn test_nonexistent_id(rt: TestRuntime) -> anyhow::Result<()> {
221224
#[convex_macro::test_runtime]
222225
async fn test_private_system_table(rt: TestRuntime) -> anyhow::Result<()> {
223226
// TODO: Reenable isolate2 when we implement table filter.
224-
UdfTest::run_test_with_isolate(rt, async move |t| {
227+
UdfTest::run_test_with_isolate(rt, async move |t: UdfTestType| {
225228
let mut tx = t.database.begin(Identity::system()).await?;
226229

227230
// backend state automatically created by with_model().
@@ -251,7 +254,7 @@ async fn test_private_system_table(rt: TestRuntime) -> anyhow::Result<()> {
251254

252255
#[convex_macro::test_runtime]
253256
async fn test_unhandled_promise_rejection(rt: TestRuntime) -> anyhow::Result<()> {
254-
UdfTest::run_test_with_isolate2(rt, async move |t| {
257+
UdfTest::run_test_with_isolate2(rt, async move |t: UdfTestType| {
255258
// Check that an unhandled promise rejection fails the UDF.
256259
let e = t
257260
.mutation_js_error("userError:unhandledRejection", assert_obj!())
@@ -264,7 +267,7 @@ async fn test_unhandled_promise_rejection(rt: TestRuntime) -> anyhow::Result<()>
264267

265268
#[convex_macro::test_runtime]
266269
async fn test_catching_async_exception_thrown_before_await(rt: TestRuntime) -> anyhow::Result<()> {
267-
UdfTest::run_test_with_isolate2(rt, async move |t| {
270+
UdfTest::run_test_with_isolate2(rt, async move |t: UdfTestType| {
268271
must_let!(let Ok(ConvexValue::String(s)) = t.mutation("userError:asyncExceptionBeforeAwait", assert_obj!()).await);
269272
assert!(s.contains("This is a custom exception"), "{s}");
270273
Ok(())
@@ -273,7 +276,7 @@ async fn test_catching_async_exception_thrown_before_await(rt: TestRuntime) -> a
273276

274277
#[convex_macro::test_runtime]
275278
async fn test_catching_async_exception_thrown_after_await(rt: TestRuntime) -> anyhow::Result<()> {
276-
UdfTest::run_test_with_isolate2(rt, async move |t| {
279+
UdfTest::run_test_with_isolate2(rt, async move |t: UdfTestType| {
277280
must_let!(let Ok(ConvexValue::String(s)) = t.mutation("userError:asyncExceptionAfterAwait", assert_obj!()).await);
278281
assert!(s.contains("This is a custom exception"), "{s}");
279282
Ok(())
@@ -282,7 +285,7 @@ async fn test_catching_async_exception_thrown_after_await(rt: TestRuntime) -> an
282285

283286
#[convex_macro::test_runtime]
284287
async fn test_throw_string(rt: TestRuntime) -> anyhow::Result<()> {
285-
UdfTest::run_test_with_isolate2(rt, async move |t| {
288+
UdfTest::run_test_with_isolate2(rt, async move |t: UdfTestType| {
286289
must_let!(let Ok(ConvexValue::String(s)) = t.mutation("userError:throwString", assert_obj!()).await);
287290
assert!(s.contains("string - a string"), "{s}");
288291
Ok(())
@@ -291,7 +294,7 @@ async fn test_throw_string(rt: TestRuntime) -> anyhow::Result<()> {
291294

292295
#[convex_macro::test_runtime]
293296
async fn test_async_syscall_error(rt: TestRuntime) -> anyhow::Result<()> {
294-
UdfTest::run_test_with_isolate2(rt, async move |t| {
297+
UdfTest::run_test_with_isolate2(rt, async move |t: UdfTestType| {
295298
let e = t
296299
.mutation_js_error("userError:syscallError", assert_obj!())
297300
.await?;
@@ -308,7 +311,7 @@ async fn test_async_syscall_error(rt: TestRuntime) -> anyhow::Result<()> {
308311

309312
#[convex_macro::test_runtime]
310313
async fn test_insert_with_creation_time(rt: TestRuntime) -> anyhow::Result<()> {
311-
UdfTest::run_test_with_isolate2(rt, async move |t| {
314+
UdfTest::run_test_with_isolate2(rt, async move |t: UdfTestType| {
312315
let e = t
313316
.mutation_js_error("adversarial:insertWithCreationTime", assert_obj!())
314317
.await?;
@@ -320,7 +323,7 @@ async fn test_insert_with_creation_time(rt: TestRuntime) -> anyhow::Result<()> {
320323

321324
#[convex_macro::test_runtime]
322325
async fn test_insert_with_id(rt: TestRuntime) -> anyhow::Result<()> {
323-
UdfTest::run_test_with_isolate2(rt, async move |t| {
326+
UdfTest::run_test_with_isolate2(rt, async move |t: UdfTestType| {
324327
let e = t
325328
.mutation_js_error("adversarial:insertWithId", assert_obj!())
326329
.await?;

0 commit comments

Comments
 (0)