Skip to content

Commit

Permalink
feat(bin): add random suffix to the temporary databases
Browse files Browse the repository at this point in the history
Signed-off-by: xxchan <[email protected]>
  • Loading branch information
xxchan committed Apr 17, 2024
1 parent 38030ac commit fa4cc21
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 37 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## [0.20.1] - 2024-04-17

* bin: When using `-j <jobs>` to run tests in parallel, add a random suffix to the temporary databases. This is useful if the test is manually canceled, but you want to rerun it freshly. Note that if the test failed, the database will be dropped. This is existing behavior and unchanged.
* bin: replace `env_logger` with `tracing-subscriber`. You will be able to see the record being executed with `RUST_LOG=debug sqllogictest ...`.

## [0.20.0] - 2024-04-08

* Show stdout, stderr when `system` command fails.
Expand Down
100 changes: 72 additions & 28 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.20.0"
version = "0.20.1"
edition = "2021"
homepage = "https://github.com/risinglightdb/sqllogictest-rs"
keywords = ["sql", "database", "parser", "cli"]
Expand Down
3 changes: 2 additions & 1 deletion sqllogictest-bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ async-trait = "0.1"
chrono = { version = "0.4" }
clap = { version = "4", features = ["derive", "env"] }
console = { version = "0.15" }
env_logger = { version = "0.10" }
futures = { version = "0.3", default-features = false }
glob = "0.3"
itertools = "0.11"
Expand All @@ -35,3 +34,5 @@ tokio = { version = "1", features = [
"process",
] }
fs-err = "2.9.0"
tracing-subscriber= "0.3"
tracing = "0.1"
25 changes: 18 additions & 7 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;
use std::collections::{BTreeMap, BTreeSet};
use std::io::{stdout, Read, Seek, SeekFrom, Write};
use std::path::{Path, PathBuf};
use std::time::{Duration, Instant};
Expand All @@ -14,6 +14,7 @@ use fs_err::{File, OpenOptions};
use futures::StreamExt;
use itertools::Itertools;
use quick_junit::{NonSuccessKind, Report, TestCase, TestCaseStatus, TestSuite};
use rand::distributions::DistString;
use rand::seq::SliceRandom;
use sqllogictest::{
default_validator, strict_column_validator, update_record_with_output, AsyncDB, Injected,
Expand Down Expand Up @@ -130,7 +131,7 @@ impl DBConfig {

#[tokio::main]
pub async fn main() -> Result<()> {
env_logger::init();
tracing_subscriber::fmt::init();

let cli = Opt::command().disable_help_flag(true).arg(
Arg::new("help")
Expand Down Expand Up @@ -265,15 +266,25 @@ async fn run_parallel(
junit: Option<String>,
) -> Result<()> {
let mut create_databases = BTreeMap::new();
let mut filenames = BTreeSet::new();
for file in files {
let db_name = file
let filename = file
.to_str()
.ok_or_else(|| anyhow!("not a UTF-8 filename"))?;
let db_name = db_name.replace([' ', '.', '-', '/'], "_");
eprintln!("+ Discovered Test: {db_name}");
if create_databases.insert(db_name.to_string(), file).is_some() {
return Err(anyhow!("duplicated file name found: {}", db_name));
let normalized_filename = filename.replace([' ', '.', '-', '/'], "_");
eprintln!("+ Discovered Test: {normalized_filename}");
if !filenames.insert(normalized_filename.clone()) {
return Err(anyhow!(
"duplicated file name found: {}",
normalized_filename
));
}
let random_id: String = rand::distributions::Alphanumeric
.sample_string(&mut rand::thread_rng(), 8)
.to_lowercase();
let db_name = format!("{normalized_filename}_{random_id}");

create_databases.insert(db_name, file);
}

let mut db = engines::connect(engine, &config).await?;
Expand Down

0 comments on commit fa4cc21

Please sign in to comment.