Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: fuzz test alter table add columns #5008

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions tests-fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ datatypes = { workspace = true }
derive_builder = { workspace = true }
dotenv = "0.15"
futures = { workspace = true }
greptime-proto.workspace = true
humantime = { workspace = true }
k8s-openapi = { version = "0.22", features = ["v1_30"] }
kube = { version = "0.92", features = [
Expand All @@ -42,13 +43,16 @@ libfuzzer-sys = "0.4"
nix = { version = "0.28", features = ["process", "signal"], optional = true }
partition = { workspace = true }
paste.workspace = true
prometheus.workspace = true
prost.workspace = true
rand = { workspace = true }
rand_chacha = "0.3.1"
reqwest = { workspace = true }
schemars = "0.8"
serde = { workspace = true }
serde_json = { workspace = true }
serde_yaml = "0.9"
servers.workspace = true
snafu = { workspace = true }
sql = { workspace = true }
sqlparser.workspace = true
Expand Down Expand Up @@ -87,6 +91,13 @@ test = false
bench = false
doc = false

[[bin]]
name = "fuzz_concurr_prom_remote_write"
path = "targets/fuzz_concurr_prom_remote_write.rs"
test = false
bench = false
doc = false

[[bin]]
name = "fuzz_insert_logical_table"
path = "targets/fuzz_insert_logical_table.rs"
Expand All @@ -101,6 +112,13 @@ test = false
bench = false
doc = false

[[bin]]
name = "fuzz_concurr_alter_table"
path = "targets/fuzz_concurr_alter_table.rs"
test = false
bench = false
doc = false

[[bin]]
name = "fuzz_alter_logical_table"
path = "targets/ddl/fuzz_alter_logical_table.rs"
Expand Down
8 changes: 8 additions & 0 deletions tests-fuzz/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ Set the GreptimeDB MySQL address.
```
GT_MYSQL_ADDR = localhost:4002
```
and http address:
```
GT_HTTP_ADDR=localhost:4000
```
and fuzz build path when compiling the fuzzer using `cargo fuzz`(if you want to keep the build dir clean):
```
CARGO_TARGET_DIR="fuzz_build"
```

### For unstable fuzz tests
Set the binary path of the GreptimeDB:
Expand Down
23 changes: 23 additions & 0 deletions tests-fuzz/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use common_error::ext::BoxedError;
use common_macro::stack_trace_debug;
use snafu::{Location, Snafu};

Expand Down Expand Up @@ -111,4 +112,26 @@ pub enum Error {
error: nix::Error,
pid: Pid,
},

#[snafu(display("External Error"))]
External {
#[snafu(implicit)]
location: Location,
#[snafu(source)]
source: BoxedError,
},

#[snafu(display("Failed to send prometheus remote request"))]
SendPromRemoteRequest {
#[snafu(implicit)]
location: Location,
#[snafu(source)]
error: reqwest::Error,
},

#[snafu(display("Connection with database aborted"))]
ConnAborted {
#[snafu(implicit)]
location: Location,
},
}
2 changes: 1 addition & 1 deletion tests-fuzz/src/ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use std::collections::HashMap;
use std::sync::{Arc, Mutex};
use std::time::Duration;

pub use alter_expr::{AlterTableExpr, AlterTableOption};
pub use alter_expr::{AlterTableExpr, AlterTableOperation, AlterTableOption};
use common_time::timestamp::TimeUnit;
use common_time::{Date, DateTime, Timestamp};
pub use create_expr::{CreateDatabaseExpr, CreateTableExpr};
Expand Down
15 changes: 12 additions & 3 deletions tests-fuzz/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ use crate::ir::Ident;
/// Database connections
pub struct Connections {
pub mysql: Option<Pool<MySql>>,
pub http: Option<String>,
}

const GT_MYSQL_ADDR: &str = "GT_MYSQL_ADDR";
const GT_HTTP_ADDR: &str = "GT_HTTP_ADDR";

/// Connects to GreptimeDB via env variables.
pub async fn init_greptime_connections_via_env() -> Connections {
Expand All @@ -53,11 +55,18 @@ pub async fn init_greptime_connections_via_env() -> Connections {
None
};

init_greptime_connections(mysql).await
let http = if let Ok(addr) = env::var(GT_HTTP_ADDR) {
Some(addr)
} else {
info!("GT_HTTP_ADDR is empty, ignores test");
None
};

init_greptime_connections(mysql, http).await
}

/// Connects to GreptimeDB.
pub async fn init_greptime_connections(mysql: Option<String>) -> Connections {
pub async fn init_greptime_connections(mysql: Option<String>, http: Option<String>) -> Connections {
let mysql = if let Some(addr) = mysql {
let mut opts: MySqlConnectOptions = format!("mysql://{addr}/public").parse().unwrap();
opts.log_statements(LevelFilter::Off);
Expand All @@ -66,7 +75,7 @@ pub async fn init_greptime_connections(mysql: Option<String>) -> Connections {
None
};

Connections { mysql }
Connections { mysql, http }
}

const GT_FUZZ_BINARY_PATH: &str = "GT_FUZZ_BINARY_PATH";
Expand Down
2 changes: 1 addition & 1 deletion tests-fuzz/targets/ddl/fuzz_alter_logical_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ async fn execute_alter_table(ctx: FuzzContext, input: FuzzInput) -> Result<()> {
fuzz_target!(|input: FuzzInput| {
common_telemetry::init_default_ut_logging();
common_runtime::block_on_global(async {
let Connections { mysql } = init_greptime_connections_via_env().await;
let Connections { mysql, .. } = init_greptime_connections_via_env().await;
let ctx = FuzzContext {
greptime: mysql.expect("mysql connection init must be succeed"),
};
Expand Down
2 changes: 1 addition & 1 deletion tests-fuzz/targets/ddl/fuzz_alter_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ async fn execute_alter_table(ctx: FuzzContext, input: FuzzInput) -> Result<()> {
fuzz_target!(|input: FuzzInput| {
common_telemetry::init_default_ut_logging();
common_runtime::block_on_global(async {
let Connections { mysql } = init_greptime_connections_via_env().await;
let Connections { mysql, .. } = init_greptime_connections_via_env().await;
let ctx = FuzzContext {
greptime: mysql.expect("mysql connection init must be succeed"),
};
Expand Down
2 changes: 1 addition & 1 deletion tests-fuzz/targets/ddl/fuzz_create_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ async fn execute_create_database(ctx: FuzzContext, input: FuzzInput) -> Result<(
fuzz_target!(|input: FuzzInput| {
common_telemetry::init_default_ut_logging();
common_runtime::block_on_global(async {
let Connections { mysql } = init_greptime_connections_via_env().await;
let Connections { mysql, .. } = init_greptime_connections_via_env().await;
let ctx = FuzzContext {
greptime: mysql.expect("mysql connection init must be succeed"),
};
Expand Down
2 changes: 1 addition & 1 deletion tests-fuzz/targets/ddl/fuzz_create_logical_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ async fn execute_create_logic_table(ctx: FuzzContext, input: FuzzInput) -> Resul
fuzz_target!(|input: FuzzInput| {
common_telemetry::init_default_ut_logging();
common_runtime::block_on_global(async {
let Connections { mysql } = init_greptime_connections_via_env().await;
let Connections { mysql, .. } = init_greptime_connections_via_env().await;
let ctx = FuzzContext {
greptime: mysql.expect("mysql connection init must be succeed"),
};
Expand Down
2 changes: 1 addition & 1 deletion tests-fuzz/targets/ddl/fuzz_create_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ async fn execute_create_table(ctx: FuzzContext, input: FuzzInput) -> Result<()>
fuzz_target!(|input: FuzzInput| {
common_telemetry::init_default_ut_logging();
common_runtime::block_on_global(async {
let Connections { mysql } = init_greptime_connections_via_env().await;
let Connections { mysql, .. } = init_greptime_connections_via_env().await;
let ctx = FuzzContext {
greptime: mysql.expect("mysql connection init must be succeed"),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ async fn execute_failover(ctx: FuzzContext, input: FuzzInput) -> Result<()> {
fuzz_target!(|input: FuzzInput| {
common_telemetry::init_default_ut_logging();
common_runtime::block_on_global(async {
let Connections { mysql } = init_greptime_connections_via_env().await;
let Connections { mysql, .. } = init_greptime_connections_via_env().await;
let ctx = FuzzContext {
greptime: mysql.expect("mysql connection init must be succeed"),
kube: kube::client::Client::try_default()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ async fn execute_failover(ctx: FuzzContext, input: FuzzInput) -> Result<()> {
fuzz_target!(|input: FuzzInput| {
common_telemetry::init_default_ut_logging();
common_runtime::block_on_global(async {
let Connections { mysql } = init_greptime_connections_via_env().await;
let Connections { mysql, .. } = init_greptime_connections_via_env().await;
let ctx = FuzzContext {
greptime: mysql.expect("mysql connection init must be succeed"),
kube: kube::client::Client::try_default()
Expand Down
Loading
Loading