Skip to content

Commit

Permalink
feat: support system ok retry (#245)
Browse files Browse the repository at this point in the history
* feat: support `system ok retry`

Signed-off-by: xxchan <[email protected]>

* enhance tests

Signed-off-by: xxchan <[email protected]>

* fmt

Signed-off-by: xxchan <[email protected]>

---------

Signed-off-by: xxchan <[email protected]>
  • Loading branch information
xxchan authored Jan 9, 2025
1 parent 7b86552 commit 1341f2c
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 8 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## [0.26.1] - 2025-01-08

* parser/runner: support `system ok retry`

## [0.26.0] - 2025-01-06

* paser: Add back `label` support, which was removed in 0.25.0.
* parser: Add back `label` support, which was removed in 0.25.0.
* parser/runner: support `[statement|query] error retry` (Only support multi-line error message)

## [0.25.0] - 2024-12-26
Expand Down
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ resolver = "2"
members = ["sqllogictest", "sqllogictest-bin", "sqllogictest-engines", "tests"]

[workspace.package]
version = "0.26.0"
version = "0.26.1"
edition = "2021"
homepage = "https://github.com/risinglightdb/sqllogictest-rs"
keywords = ["sql", "database", "parser", "cli"]
Expand Down
20 changes: 17 additions & 3 deletions sqllogictest/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ pub enum Record<T: ColumnType> {
/// The external command.
command: String,
stdout: Option<String>,
/// Optional retry configuration
retry: Option<RetryConfig>,
},
/// A sleep period.
Sleep {
Expand Down Expand Up @@ -302,8 +304,17 @@ impl<T: ColumnType> std::fmt::Display for Record<T> {
conditions: _,
command,
stdout,
retry,
} => {
writeln!(f, "system ok\n{command}")?;
if let Some(retry) = retry {
write!(
f,
" retry {} backoff {}",
retry.attempts,
humantime::format_duration(retry.backoff)
)?;
}
if let Some(stdout) = stdout {
writeln!(f, "----\n{}\n", stdout.trim())?;
}
Expand Down Expand Up @@ -898,7 +909,9 @@ fn parse_inner<T: ColumnType>(loc: &Location, script: &str) -> Result<Vec<Record
retry,
});
}
["system", "ok"] => {
["system", "ok", res @ ..] => {
let retry = parse_retry_config(res).map_err(|e| e.at(loc.clone()))?;

// TODO: we don't support asserting error message for system command
// The command is found on second and subsequent lines of the record
// up to first line of the form "----" or until the end of the record.
Expand All @@ -913,6 +926,7 @@ fn parse_inner<T: ColumnType>(loc: &Location, script: &str) -> Result<Vec<Record
conditions: std::mem::take(&mut conditions),
command,
stdout,
retry,
});
}
["control", res @ ..] => match res {
Expand Down Expand Up @@ -1327,11 +1341,11 @@ select * from foo;

#[test]
fn test_statement_retry() {
parse_roundtrip::<DefaultColumnType>("../tests/retry/statement_retry.slt")
parse_roundtrip::<DefaultColumnType>("../tests/no_run/statement_retry.slt")
}

#[test]
fn test_query_retry() {
parse_roundtrip::<DefaultColumnType>("../tests/retry/query_retry.slt")
parse_roundtrip::<DefaultColumnType>("../tests/no_run/query_retry.slt")
}
}
5 changes: 5 additions & 0 deletions sqllogictest/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,7 @@ impl<D: AsyncDB, M: MakeConnection<Conn = D>> Runner<D, M> {
command,
loc: _,
stdout: expected_stdout,
retry: _,
} => {
if should_skip(&self.labels, "", &conditions) {
return RecordOutput::Nothing;
Expand Down Expand Up @@ -885,6 +886,7 @@ impl<D: AsyncDB, M: MakeConnection<Conn = D>> Runner<D, M> {
let retry = match &record {
Record::Statement { retry, .. } => retry.clone(),
Record::Query { retry, .. } => retry.clone(),
Record::System { retry, .. } => retry.clone(),
_ => None,
};
if retry.is_none() {
Expand Down Expand Up @@ -1099,6 +1101,7 @@ impl<D: AsyncDB, M: MakeConnection<Conn = D>> Runner<D, M> {
conditions: _,
command,
stdout: expected_stdout,
retry: _,
},
RecordOutput::System {
error,
Expand Down Expand Up @@ -1668,6 +1671,7 @@ pub fn update_record_with_output<T: ColumnType>(
conditions,
command,
stdout: _,
retry,
},
RecordOutput::System {
stdout: actual_stdout,
Expand All @@ -1686,6 +1690,7 @@ pub fn update_record_with_output<T: ColumnType>(
conditions,
command,
stdout: actual_stdout.clone(),
retry,
})
}

Expand Down
1 change: 1 addition & 0 deletions tests/no_run/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Tests in this directory are not run. They are used only for testing the parser.
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions tests/no_run/system_retry.slt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
system ok retry 3 backoff 5s
echo "hello"
----
hell
9 changes: 9 additions & 0 deletions tests/slt/retry.slt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
query I retry 3 backoff 0s
select counter()
----
3

system ok retry 3 backoff 1ms1ns
echo "hello"
----
hello

0 comments on commit 1341f2c

Please sign in to comment.