Skip to content

Commit

Permalink
feat(bin): add opt --keep-db-on-failure
Browse files Browse the repository at this point in the history
Signed-off-by: xxchan <[email protected]>
  • Loading branch information
xxchan committed Dec 12, 2024
1 parent a38886a commit 92b350d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## [0.23.1] - 2024-12-13

* feat(bin): add opt `--keep-db-on-failure`

## [0.23.0] - 2024-11-16

* Refine the behavior of `update_record_with_output` / `--override`
Expand Down
27 changes: 23 additions & 4 deletions sqllogictest-bin/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mod engines;

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

/// Report to junit XML.
#[clap(long)]
Expand Down Expand Up @@ -146,6 +149,7 @@ pub async fn main() -> Result<()> {
external_engine_command_template,
color,
jobs,
keep_db_on_failure,
junit,
host,
port,
Expand Down Expand Up @@ -228,6 +232,7 @@ pub async fn main() -> Result<()> {
let result = if let Some(jobs) = jobs {
run_parallel(
jobs,
keep_db_on_failure,
&mut test_suite,
files,
&engine,
Expand Down Expand Up @@ -259,6 +264,7 @@ pub async fn main() -> Result<()> {

async fn run_parallel(
jobs: usize,
keep_db_on_failure: bool,
test_suite: &mut TestSuite,
files: Vec<PathBuf>,
engine: &EngineConfig,
Expand Down Expand Up @@ -302,7 +308,7 @@ async fn run_parallel(
let mut stream = futures::stream::iter(create_databases.into_iter())
.map(|(db_name, filename)| {
let mut config = config.clone();
config.db = db_name;
config.db = db_name.clone();
let file = filename.to_string_lossy().to_string();
let engine = engine.clone();
let labels = labels.to_vec();
Expand All @@ -316,18 +322,19 @@ async fn run_parallel(
})
.await
.unwrap();
(file, res, buf)
(db_name, file, res, buf)
}
})
.buffer_unordered(jobs);

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

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

let start = Instant::now();

while let Some((file, res, mut buf)) = stream.next().await {
while let Some((db_name, file, res, mut buf)) = stream.next().await {
let test_case_name = file.replace(['/', ' ', '.', '-'], "_");
let case = match res {
Ok(duration) => {
Expand All @@ -341,6 +348,7 @@ async fn run_parallel(
writeln!(buf, "{}\n\n{:?}", style("[FAILED]").red().bold(), e)?;
writeln!(buf)?;
failed_case.push(file.clone());
failed_db.insert(db_name.clone());
let mut status = TestCaseStatus::non_success(NonSuccessKind::Failure);
status.set_type("test failure");
let mut case = TestCase::new(test_case_name, status);
Expand All @@ -362,6 +370,17 @@ async fn run_parallel(
);

for db_name in db_names {
if keep_db_on_failure && failed_db.contains(&db_name) {
eprintln!(
"+ {}",
style(format!(
"DATABASE {db_name} contains failed cases, kept for debugging"
))
.red()
.bold()
);
continue;
}
let query = format!("DROP DATABASE {db_name};");
eprintln!("+ {query}");
if let Err(err) = db.run(&query).await {
Expand Down

0 comments on commit 92b350d

Please sign in to comment.