From 9ed5071f63c49985deb339b938fe2f45fa329ac2 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Wed, 23 Oct 2024 03:44:43 +0200 Subject: [PATCH] fix standalone_integration_test --- .../tests/standalone_integration_test.rs | 62 +++++++++---------- 1 file changed, 28 insertions(+), 34 deletions(-) diff --git a/crates/testing/tests/standalone_integration_test.rs b/crates/testing/tests/standalone_integration_test.rs index 3f458f4d9e5..a785316ff77 100644 --- a/crates/testing/tests/standalone_integration_test.rs +++ b/crates/testing/tests/standalone_integration_test.rs @@ -37,6 +37,23 @@ async fn read_logs(module: &ModuleHandle) -> Vec { .collect::>() } +async fn call_reducer(module: &ModuleHandle, reducer: &str, args: &str, request_id: u32) { + let reducer_id = module.client.module.info().reducers_map.lookup_id(reducer).unwrap(); + + let json = format!( + r#"{{ + "CallReducer": {{ + "reducer_id": {reducer_id}, + "args": {args}, + "request_id": {request_id}, + "flags": 0 + }} + }}"# + ) + .to_string(); + module.send(json).await.unwrap(); +} + // The tests MUST be run in sequence because they read the OS environment // and can cause a race when run in parallel. @@ -46,24 +63,10 @@ fn test_calling_a_reducer_in_module(module_name: &'static str) { CompiledModule::compile(module_name, CompilationMode::Debug).with_module_async( DEFAULT_CONFIG, |module| async move { - let json = - r#"{"CallReducer": {"reducer": "add", "args": "[\"Tyrion\", 24]", "request_id": 0, "flags": 0 }}"# - .to_string(); - module.send(json).await.unwrap(); - - let json = - r#"{"CallReducer": {"reducer": "add", "args": "[\"Cersei\", 31]", "request_id": 1, "flags": 0 }}"# - .to_string(); - module.send(json).await.unwrap(); - - let json = - r#"{"CallReducer": {"reducer": "say_hello", "args": "[]", "request_id": 2, "flags": 0 }}"#.to_string(); - module.send(json).await.unwrap(); - - let json = r#"{"CallReducer": {"reducer": "list_over_age", "args": "[30]", "request_id": 3, "flags": 0 }}"# - .to_string(); - module.send(json).await.unwrap(); - + call_reducer(&module, "add", "[\"Tyrion\", 24]", 0).await; + call_reducer(&module, "add", "[\"Cersei\", 31]", 1).await; + call_reducer(&module, "say_hello", "[]", 2).await; + call_reducer(&module, "list_over_age", "[30]", 3).await; assert_eq!( read_logs(&module).await, [ @@ -174,16 +177,11 @@ fn test_call_query_macro() { // Hand-written JSON. This will fail if the JSON encoding of `ClientMessage` changes. test_call_query_macro_with_caller(|module| async move { // Note that JSON doesn't allow multiline strings, so the encoded args string must be on one line! - let json = r#" -{ "CallReducer": { - "reducer": "test", - "args": - "[ { \"x\": 0, \"y\": 2, \"z\": \"Macro\" }, { \"foo\": \"Foo\" }, { \"Foo\": {} }, { \"Baz\": \"buzz\" } ]", - "request_id": 0, - "flags": 0 -} }"# - .to_string(); - module.send(json).await.unwrap(); + call_reducer( + &module, + "test", "[ { \"x\": 0, \"y\": 2, \"z\": \"Macro\" }, { \"foo\": \"Foo\" }, { \"Foo\": {} }, { \"Baz\": \"buzz\" } ]", + 0, + ).await; }); let args_pv = product![ @@ -256,13 +254,9 @@ fn test_index_scans() { } async fn bench_call<'a>(module: &ModuleHandle, call: &str, count: &u32) -> Duration { - let json = - format!(r#"{{"CallReducer": {{"reducer": "{call}", "args": "[{count}]", "request_id": 0, "flags": 0 }}}}"#); - + let args = format!("\"[{count}]\""); let now = Instant::now(); - - module.send(json).await.unwrap(); - + call_reducer(module, call, &args, 0).await; now.elapsed() }