-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support arbitrary RHS in C# Query #586
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
use serde_json::Value; | ||
use serial_test::serial; | ||
use spacetimedb_testing::modules::{CompilationMode, CompiledModule, DEFAULT_CONFIG}; | ||
use spacetimedb_testing::modules::{ | ||
CompilationMode, CompiledModule, LogLevel, LoggerRecord, ModuleHandle, DEFAULT_CONFIG, | ||
}; | ||
|
||
fn init() { | ||
let _ = env_logger::builder() | ||
|
@@ -13,6 +14,24 @@ fn init() { | |
.try_init(); | ||
} | ||
|
||
async fn read_logs(module: &ModuleHandle) -> Vec<String> { | ||
module | ||
.read_log(None) | ||
.await | ||
.trim() | ||
.split('\n') | ||
.map(|line| { | ||
let record: LoggerRecord = serde_json::from_str(line).unwrap(); | ||
if matches!(record.level, LogLevel::Panic | LogLevel::Error | LogLevel::Warn) { | ||
panic!("Found an error-like log line: {line}"); | ||
} | ||
record.message | ||
}) | ||
.skip_while(|line| line != "Database initialized") | ||
.skip(1) | ||
.collect::<Vec<_>>() | ||
} | ||
|
||
// The tests MUST be run in sequence because they read the OS environment | ||
// and can cause a race when run in parallel. | ||
|
||
|
@@ -22,27 +41,28 @@ 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#"{"call": {"fn": "add", "args": ["Tyrion"]}}"#.to_string(); | ||
module.send(json).await.unwrap(); | ||
let json = r#"{"call": {"fn": "say_hello", "args": []}}"#.to_string(); | ||
let json = r#"{"call": {"fn": "add", "args": ["Tyrion", 24]}}"#.to_string(); | ||
module.send(json).await.unwrap(); | ||
|
||
let lines: Vec<Value> = module | ||
.read_log(Some(10)) | ||
.await | ||
.trim() | ||
.split('\n') | ||
.map(serde_json::from_str) | ||
.collect::<serde_json::Result<_>>() | ||
.unwrap(); | ||
let json = r#"{"call": {"fn": "add", "args": ["Cersei", 31]}}"#.to_string(); | ||
module.send(json).await.unwrap(); | ||
|
||
assert!(lines.len() >= 4); | ||
let json = r#"{"call": {"fn": "say_hello", "args": []}}"#.to_string(); | ||
module.send(json).await.unwrap(); | ||
|
||
assert_eq!(lines[lines.len() - 2]["level"], "Info"); | ||
assert_eq!(lines[lines.len() - 2]["message"], "Hello, Tyrion!"); | ||
let json = r#"{"call": {"fn": "list_over_age", "args": [30]}}"#.to_string(); | ||
module.send(json).await.unwrap(); | ||
|
||
assert_eq!(lines[lines.len() - 1]["level"], "Info"); | ||
assert_eq!(lines[lines.len() - 1]["message"], "Hello, World!"); | ||
assert_eq!( | ||
read_logs(&module).await, | ||
[ | ||
"Hello, Tyrion!", | ||
"Hello, Cersei!", | ||
"Hello, World!", | ||
"Cersei has age 31 >= 30", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I bet she'd deny it. |
||
] | ||
.map(String::from) | ||
); | ||
}, | ||
); | ||
} | ||
|
@@ -72,15 +92,10 @@ fn test_calling_a_reducer_with_private_table() { | |
let json = r#"{"call": {"fn": "query_private", "args": []}}"#.to_string(); | ||
module.send(json).await.unwrap(); | ||
|
||
let lines = module.read_log(Some(11)).await; | ||
let lines: Vec<&str> = lines.trim().split('\n').collect(); | ||
|
||
assert_eq!(lines.len(), 10); | ||
|
||
let json: Value = serde_json::from_str(lines[8]).unwrap(); | ||
assert_eq!(json["message"], Value::String("Private, Tyrion!".to_string())); | ||
let json: Value = serde_json::from_str(lines[9]).unwrap(); | ||
assert_eq!(json["message"], Value::String("Private, World!".to_string())); | ||
assert_eq!( | ||
read_logs(&module).await, | ||
["Private, Tyrion!", "Private, World!",].map(String::from) | ||
); | ||
}, | ||
); | ||
} | ||
|
@@ -92,38 +107,34 @@ fn test_call_query_macro() { | |
DEFAULT_CONFIG, | ||
|module| async move { | ||
let json = r#" | ||
{"call": {"fn": "test", "args":[ | ||
{"call": {"fn": "test", "args":[ | ||
{"x":0, "y":2, "z":"Macro"}, | ||
{"foo":"Foo"}, | ||
{"Foo": {} } | ||
]}}"# | ||
.to_string(); | ||
module.send(json).await.unwrap(); | ||
|
||
let lines = module.read_log(Some(13)).await; | ||
let lines: Vec<&str> = lines.trim().split('\n').collect(); | ||
let logs = read_logs(&module).await; | ||
|
||
assert_eq!(lines.len(), 13); | ||
assert_eq!(logs[0], "BEGIN"); | ||
assert!(logs[1].starts_with("sender: ")); | ||
assert!(logs[2].starts_with("timestamp: ")); | ||
|
||
let json: Value = serde_json::from_str(lines[6]).unwrap(); | ||
assert_eq!( | ||
json["message"], | ||
Value::String("Row count before delete: 1000".to_string()) | ||
); | ||
let json: Value = serde_json::from_str(lines[8]).unwrap(); | ||
assert_eq!( | ||
json["message"], | ||
Value::String("Row count after delete: 995".to_string()) | ||
); | ||
let json: Value = serde_json::from_str(lines[9]).unwrap(); | ||
assert_eq!( | ||
json["message"], | ||
Value::String("Row count filtered by condition: 995".to_string()) | ||
); | ||
let json: Value = serde_json::from_str(lines[11]).unwrap(); | ||
assert_eq!( | ||
json["message"], | ||
Value::String("Row count filtered by multi-column condition: 199".to_string()) | ||
logs[3..], | ||
[ | ||
r#"bar: "Foo""#, | ||
"Foo", | ||
"Row count before delete: 1000", | ||
r#"Inserted: TestE { id: 1, name: "Tyler" }"#, | ||
"Row count after delete: 995", | ||
"Row count filtered by condition: 995", | ||
"MultiColumn", | ||
"Row count filtered by multi-column condition: 199", | ||
"END", | ||
] | ||
.map(String::from) | ||
); | ||
}, | ||
); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know what
Rust!
means here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Me neither. This code was just moved around.