Skip to content

Commit

Permalink
fix(fuzz-tests): avoid to drop in-use database
Browse files Browse the repository at this point in the history
  • Loading branch information
WenyXu committed May 27, 2024
1 parent af486ec commit e10d7f5
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions tests-fuzz/targets/unstable/fuzz_create_table_standalone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ fn generate_create_table_expr<R: Rng + 'static>(rng: &mut R) -> CreateTableExpr
create_table_generator.generate(rng).unwrap()
}

async fn connect_mysql(addr: &str) -> Pool<MySql> {
async fn connect_mysql(addr: &str, database: &str) -> Pool<MySql> {
loop {
match MySqlPoolOptions::new()
.acquire_timeout(Duration::from_secs(30))
.connect(&format!("mysql://{addr}/public"))
.connect(&format!("mysql://{addr}/{database}"))
.await
{
Ok(mysql) => return mysql,
Expand All @@ -114,13 +114,17 @@ async fn execute_unstable_create_table(
rx: watch::Receiver<ProcessState>,
input: FuzzInput,
) -> Result<()> {
let mysql_public = connect_mysql(DEFAULT_MYSQL_URL, "public").await;
let mysql = sqlx::query("CREATE DATABASE fuzz_tests")
.execute(&mysql_public)
.await
.expect("Failed to create database 'fuzz_tests'");

// Starts the unstable process.
let moved_unstable_process_controller = unstable_process_controller.clone();
let handler = tokio::spawn(async move { moved_unstable_process_controller.start().await });
let mut rng = ChaChaRng::seed_from_u64(input.seed);
let mysql = connect_mysql(DEFAULT_MYSQL_URL).await;
let ctx = FuzzContext { greptime: mysql };

let mut table_states = HashMap::new();

for _ in 0..input.num {
Expand Down Expand Up @@ -163,13 +167,13 @@ async fn execute_unstable_create_table(
}

loop {
let sql = "DROP DATABASE IF EXISTS public";
match sqlx::query(sql).execute(&ctx.greptime).await {
let sql = "DROP DATABASE IF EXISTS fuzz_tests";
match sqlx::query(sql).execute(&mysql_public).await {
Ok(result) => {
info!("Drop table: {}, result: {result:?}", sql);
info!("Drop database: {}, result: {result:?}", sql);
break;
}
Err(err) => warn!("Failed to drop table: {}, error: {err}", sql),
Err(err) => warn!("Failed to drop database: {}, error: {err}", sql),
}
}
// Cleans up
Expand Down

0 comments on commit e10d7f5

Please sign in to comment.