Skip to content

Commit 13053e0

Browse files
committed
fix standalone_integration_test
1 parent 8d846de commit 13053e0

File tree

1 file changed

+28
-34
lines changed

1 file changed

+28
-34
lines changed

crates/testing/tests/standalone_integration_test.rs

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,23 @@ async fn read_logs(module: &ModuleHandle) -> Vec<String> {
3737
.collect::<Vec<_>>()
3838
}
3939

40+
async fn call_reducer(module: &ModuleHandle, reducer: &str, args: &str, request_id: u32) {
41+
let reducer_id = module.client.module.info().reducers_map.lookup_id(reducer).unwrap();
42+
43+
let json = format!(
44+
r#"{{
45+
"CallReducer": {{
46+
"reducer_id": {reducer_id},
47+
"args": {args},
48+
"request_id": {request_id},
49+
"flags": 0
50+
}}
51+
}}"#
52+
)
53+
.to_string();
54+
module.send(json).await.unwrap();
55+
}
56+
4057
// The tests MUST be run in sequence because they read the OS environment
4158
// and can cause a race when run in parallel.
4259

@@ -46,24 +63,10 @@ fn test_calling_a_reducer_in_module(module_name: &'static str) {
4663
CompiledModule::compile(module_name, CompilationMode::Debug).with_module_async(
4764
DEFAULT_CONFIG,
4865
|module| async move {
49-
let json =
50-
r#"{"CallReducer": {"reducer": "add", "args": "[\"Tyrion\", 24]", "request_id": 0, "flags": 0 }}"#
51-
.to_string();
52-
module.send(json).await.unwrap();
53-
54-
let json =
55-
r#"{"CallReducer": {"reducer": "add", "args": "[\"Cersei\", 31]", "request_id": 1, "flags": 0 }}"#
56-
.to_string();
57-
module.send(json).await.unwrap();
58-
59-
let json =
60-
r#"{"CallReducer": {"reducer": "say_hello", "args": "[]", "request_id": 2, "flags": 0 }}"#.to_string();
61-
module.send(json).await.unwrap();
62-
63-
let json = r#"{"CallReducer": {"reducer": "list_over_age", "args": "[30]", "request_id": 3, "flags": 0 }}"#
64-
.to_string();
65-
module.send(json).await.unwrap();
66-
66+
call_reducer(&module, "add", "[\"Tyrion\", 24]", 0).await;
67+
call_reducer(&module, "add", "[\"Cersei\", 31]", 1).await;
68+
call_reducer(&module, "say_hello", "[]", 2).await;
69+
call_reducer(&module, "list_over_age", "[30]", 3).await;
6770
assert_eq!(
6871
read_logs(&module).await,
6972
[
@@ -174,16 +177,11 @@ fn test_call_query_macro() {
174177
// Hand-written JSON. This will fail if the JSON encoding of `ClientMessage` changes.
175178
test_call_query_macro_with_caller(|module| async move {
176179
// Note that JSON doesn't allow multiline strings, so the encoded args string must be on one line!
177-
let json = r#"
178-
{ "CallReducer": {
179-
"reducer": "test",
180-
"args":
181-
"[ { \"x\": 0, \"y\": 2, \"z\": \"Macro\" }, { \"foo\": \"Foo\" }, { \"Foo\": {} }, { \"Baz\": \"buzz\" } ]",
182-
"request_id": 0,
183-
"flags": 0
184-
} }"#
185-
.to_string();
186-
module.send(json).await.unwrap();
180+
call_reducer(
181+
&module,
182+
"test", "[ { \"x\": 0, \"y\": 2, \"z\": \"Macro\" }, { \"foo\": \"Foo\" }, { \"Foo\": {} }, { \"Baz\": \"buzz\" } ]",
183+
0,
184+
).await;
187185
});
188186

189187
let args_pv = product![
@@ -256,13 +254,9 @@ fn test_index_scans() {
256254
}
257255

258256
async fn bench_call<'a>(module: &ModuleHandle, call: &str, count: &u32) -> Duration {
259-
let json =
260-
format!(r#"{{"CallReducer": {{"reducer": "{call}", "args": "[{count}]", "request_id": 0, "flags": 0 }}}}"#);
261-
257+
let args = format!("[{count}]");
262258
let now = Instant::now();
263-
264-
module.send(json).await.unwrap();
265-
259+
call_reducer(module, call, &args, 0).await;
266260
now.elapsed()
267261
}
268262

0 commit comments

Comments
 (0)