Skip to content

Commit

Permalink
fix standalone_integration_test
Browse files Browse the repository at this point in the history
  • Loading branch information
Centril committed Oct 23, 2024
1 parent 8d846de commit 13053e0
Showing 1 changed file with 28 additions and 34 deletions.
62 changes: 28 additions & 34 deletions crates/testing/tests/standalone_integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,23 @@ async fn read_logs(module: &ModuleHandle) -> Vec<String> {
.collect::<Vec<_>>()
}

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.

Expand All @@ -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,
[
Expand Down Expand Up @@ -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![
Expand Down Expand Up @@ -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()
}

Expand Down

0 comments on commit 13053e0

Please sign in to comment.