Skip to content

Commit 1341f2c

Browse files
authored
feat: support system ok retry (#245)
* feat: support `system ok retry` Signed-off-by: xxchan <xxchan22f@gmail.com> * enhance tests Signed-off-by: xxchan <xxchan22f@gmail.com> * fmt Signed-off-by: xxchan <xxchan22f@gmail.com> --------- Signed-off-by: xxchan <xxchan22f@gmail.com>
1 parent 7b86552 commit 1341f2c

File tree

10 files changed

+45
-8
lines changed

10 files changed

+45
-8
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
## [0.26.1] - 2025-01-08
11+
12+
* parser/runner: support `system ok retry`
13+
1014
## [0.26.0] - 2025-01-06
1115

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

1519
## [0.25.0] - 2024-12-26

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ resolver = "2"
33
members = ["sqllogictest", "sqllogictest-bin", "sqllogictest-engines", "tests"]
44

55
[workspace.package]
6-
version = "0.26.0"
6+
version = "0.26.1"
77
edition = "2021"
88
homepage = "https://github.com/risinglightdb/sqllogictest-rs"
99
keywords = ["sql", "database", "parser", "cli"]

sqllogictest/src/parser.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ pub enum Record<T: ColumnType> {
158158
/// The external command.
159159
command: String,
160160
stdout: Option<String>,
161+
/// Optional retry configuration
162+
retry: Option<RetryConfig>,
161163
},
162164
/// A sleep period.
163165
Sleep {
@@ -302,8 +304,17 @@ impl<T: ColumnType> std::fmt::Display for Record<T> {
302304
conditions: _,
303305
command,
304306
stdout,
307+
retry,
305308
} => {
306309
writeln!(f, "system ok\n{command}")?;
310+
if let Some(retry) = retry {
311+
write!(
312+
f,
313+
" retry {} backoff {}",
314+
retry.attempts,
315+
humantime::format_duration(retry.backoff)
316+
)?;
317+
}
307318
if let Some(stdout) = stdout {
308319
writeln!(f, "----\n{}\n", stdout.trim())?;
309320
}
@@ -898,7 +909,9 @@ fn parse_inner<T: ColumnType>(loc: &Location, script: &str) -> Result<Vec<Record
898909
retry,
899910
});
900911
}
901-
["system", "ok"] => {
912+
["system", "ok", res @ ..] => {
913+
let retry = parse_retry_config(res).map_err(|e| e.at(loc.clone()))?;
914+
902915
// TODO: we don't support asserting error message for system command
903916
// The command is found on second and subsequent lines of the record
904917
// up to first line of the form "----" or until the end of the record.
@@ -913,6 +926,7 @@ fn parse_inner<T: ColumnType>(loc: &Location, script: &str) -> Result<Vec<Record
913926
conditions: std::mem::take(&mut conditions),
914927
command,
915928
stdout,
929+
retry,
916930
});
917931
}
918932
["control", res @ ..] => match res {
@@ -1327,11 +1341,11 @@ select * from foo;
13271341

13281342
#[test]
13291343
fn test_statement_retry() {
1330-
parse_roundtrip::<DefaultColumnType>("../tests/retry/statement_retry.slt")
1344+
parse_roundtrip::<DefaultColumnType>("../tests/no_run/statement_retry.slt")
13311345
}
13321346

13331347
#[test]
13341348
fn test_query_retry() {
1335-
parse_roundtrip::<DefaultColumnType>("../tests/retry/query_retry.slt")
1349+
parse_roundtrip::<DefaultColumnType>("../tests/no_run/query_retry.slt")
13361350
}
13371351
}

sqllogictest/src/runner.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,7 @@ impl<D: AsyncDB, M: MakeConnection<Conn = D>> Runner<D, M> {
644644
command,
645645
loc: _,
646646
stdout: expected_stdout,
647+
retry: _,
647648
} => {
648649
if should_skip(&self.labels, "", &conditions) {
649650
return RecordOutput::Nothing;
@@ -885,6 +886,7 @@ impl<D: AsyncDB, M: MakeConnection<Conn = D>> Runner<D, M> {
885886
let retry = match &record {
886887
Record::Statement { retry, .. } => retry.clone(),
887888
Record::Query { retry, .. } => retry.clone(),
889+
Record::System { retry, .. } => retry.clone(),
888890
_ => None,
889891
};
890892
if retry.is_none() {
@@ -1099,6 +1101,7 @@ impl<D: AsyncDB, M: MakeConnection<Conn = D>> Runner<D, M> {
10991101
conditions: _,
11001102
command,
11011103
stdout: expected_stdout,
1104+
retry: _,
11021105
},
11031106
RecordOutput::System {
11041107
error,
@@ -1668,6 +1671,7 @@ pub fn update_record_with_output<T: ColumnType>(
16681671
conditions,
16691672
command,
16701673
stdout: _,
1674+
retry,
16711675
},
16721676
RecordOutput::System {
16731677
stdout: actual_stdout,
@@ -1686,6 +1690,7 @@ pub fn update_record_with_output<T: ColumnType>(
16861690
conditions,
16871691
command,
16881692
stdout: actual_stdout.clone(),
1693+
retry,
16891694
})
16901695
}
16911696

tests/no_run/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Tests in this directory are not run. They are used only for testing the parser.
File renamed without changes.
File renamed without changes.

tests/no_run/system_retry.slt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
system ok retry 3 backoff 5s
2+
echo "hello"
3+
----
4+
hell

tests/slt/retry.slt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
query I retry 3 backoff 0s
2+
select counter()
3+
----
4+
3
5+
6+
system ok retry 3 backoff 1ms1ns
7+
echo "hello"
8+
----
9+
hello

0 commit comments

Comments
 (0)