Skip to content

Commit e08bc06

Browse files
authored
feat(bin): add opt --keep-db-on-failure (#236)
* feat(bin): add opt `--keep-db-on-failure` Signed-off-by: xxchan <xxchan22f@gmail.com> * . Signed-off-by: xxchan <xxchan22f@gmail.com> * clippy Signed-off-by: xxchan <xxchan22f@gmail.com> --------- Signed-off-by: xxchan <xxchan22f@gmail.com>
1 parent a38886a commit e08bc06

File tree

5 files changed

+35
-11
lines changed

5 files changed

+35
-11
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
## [0.23.1] - 2024-12-13
11+
12+
* feat(bin): add opt `--keep-db-on-failure`
13+
1014
## [0.23.0] - 2024-11-16
1115

1216
* Refine the behavior of `update_record_with_output` / `--override`

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.23.0"
6+
version = "0.23.1"
77
edition = "2021"
88
homepage = "https://github.com/risinglightdb/sqllogictest-rs"
99
keywords = ["sql", "database", "parser", "cli"]

sqllogictest-bin/src/main.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
mod engines;
22

3-
use std::collections::{BTreeMap, BTreeSet};
3+
use std::collections::{BTreeMap, BTreeSet, HashSet};
44
use std::io::{stdout, Read, Seek, SeekFrom, Write};
55
use std::path::{Path, PathBuf};
66
use std::time::{Duration, Instant};
@@ -62,6 +62,9 @@ struct Opt {
6262
/// database will be created for each test file.
6363
#[clap(long, short)]
6464
jobs: Option<usize>,
65+
/// When using `-j`, whether to keep the temporary database when a test case fails.
66+
#[clap(long, default_value = "false")]
67+
keep_db_on_failure: bool,
6568

6669
/// Report to junit XML.
6770
#[clap(long)]
@@ -146,6 +149,7 @@ pub async fn main() -> Result<()> {
146149
external_engine_command_template,
147150
color,
148151
jobs,
152+
keep_db_on_failure,
149153
junit,
150154
host,
151155
port,
@@ -228,6 +232,7 @@ pub async fn main() -> Result<()> {
228232
let result = if let Some(jobs) = jobs {
229233
run_parallel(
230234
jobs,
235+
keep_db_on_failure,
231236
&mut test_suite,
232237
files,
233238
&engine,
@@ -257,8 +262,10 @@ pub async fn main() -> Result<()> {
257262
result
258263
}
259264

265+
#[allow(clippy::too_many_arguments)]
260266
async fn run_parallel(
261267
jobs: usize,
268+
keep_db_on_failure: bool,
262269
test_suite: &mut TestSuite,
263270
files: Vec<PathBuf>,
264271
engine: &EngineConfig,
@@ -302,7 +309,7 @@ async fn run_parallel(
302309
let mut stream = futures::stream::iter(create_databases.into_iter())
303310
.map(|(db_name, filename)| {
304311
let mut config = config.clone();
305-
config.db = db_name;
312+
config.db.clone_from(&db_name);
306313
let file = filename.to_string_lossy().to_string();
307314
let engine = engine.clone();
308315
let labels = labels.to_vec();
@@ -316,18 +323,19 @@ async fn run_parallel(
316323
})
317324
.await
318325
.unwrap();
319-
(file, res, buf)
326+
(db_name, file, res, buf)
320327
}
321328
})
322329
.buffer_unordered(jobs);
323330

324331
eprintln!("{}", style("[TEST IN PROGRESS]").blue().bold());
325332

326333
let mut failed_case = vec![];
334+
let mut failed_db: HashSet<String> = HashSet::new();
327335

328336
let start = Instant::now();
329337

330-
while let Some((file, res, mut buf)) = stream.next().await {
338+
while let Some((db_name, file, res, mut buf)) = stream.next().await {
331339
let test_case_name = file.replace(['/', ' ', '.', '-'], "_");
332340
let case = match res {
333341
Ok(duration) => {
@@ -341,6 +349,7 @@ async fn run_parallel(
341349
writeln!(buf, "{}\n\n{:?}", style("[FAILED]").red().bold(), e)?;
342350
writeln!(buf)?;
343351
failed_case.push(file.clone());
352+
failed_db.insert(db_name.clone());
344353
let mut status = TestCaseStatus::non_success(NonSuccessKind::Failure);
345354
status.set_type("test failure");
346355
let mut case = TestCase::new(test_case_name, status);
@@ -362,6 +371,17 @@ async fn run_parallel(
362371
);
363372

364373
for db_name in db_names {
374+
if keep_db_on_failure && failed_db.contains(&db_name) {
375+
eprintln!(
376+
"+ {}",
377+
style(format!(
378+
"DATABASE {db_name} contains failed cases, kept for debugging"
379+
))
380+
.red()
381+
.bold()
382+
);
383+
continue;
384+
}
365385
let query = format!("DROP DATABASE {db_name};");
366386
eprintln!("+ {query}");
367387
if let Err(err) = db.run(&query).await {

sqllogictest/src/runner.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ pub struct TestErrorDisplay<'a> {
154154
colorize: bool,
155155
}
156156

157-
impl<'a> Display for TestErrorDisplay<'a> {
157+
impl Display for TestErrorDisplay<'_> {
158158
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
159159
write!(
160160
f,
@@ -189,7 +189,7 @@ pub struct ParallelTestErrorDisplay<'a> {
189189
colorize: bool,
190190
}
191191

192-
impl<'a> Display for ParallelTestErrorDisplay<'a> {
192+
impl Display for ParallelTestErrorDisplay<'_> {
193193
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
194194
writeln!(f, "parallel test failed")?;
195195
write!(f, "Caused by:")?;
@@ -332,7 +332,7 @@ pub struct TestErrorKindDisplay<'a> {
332332
colorize: bool,
333333
}
334334

335-
impl<'a> Display for TestErrorKindDisplay<'a> {
335+
impl Display for TestErrorKindDisplay<'_> {
336336
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
337337
if !self.colorize {
338338
return write!(f, "{}", self.error);

0 commit comments

Comments
 (0)