Skip to content

Commit 250c46e

Browse files
committed
multi-thread test runner
Signed-off-by: Alex Chi <[email protected]>
1 parent ab9f041 commit 250c46e

File tree

16 files changed

+189
-91
lines changed

16 files changed

+189
-91
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ keywords = ["sql", "database", "planner", "cli"]
1313
[dependencies]
1414
anyhow = "1"
1515
async-trait = "0.1"
16+
console = "0.15"
17+
futures-util = { version = "0.3", default-features = false, features = ["alloc"] }
1618
glob = "0.3"
1719
libtest-mimic = "0.4"
1820
serde = { version = "1.0", features = ["derive"] }
1921
serde_yaml = "0.8"
2022
similar = "2"
2123
tokio = { version = "1", features = ["rt", "fs"] }
22-
console = "0.15"
2324

2425
[workspace]
2526
members = ["naivedb"]

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Here's an example of test description file:
1919
SELECT * FROM t1, t2 WHERE t1.v1 = t2.v2;
2020
desc: Test whether join works correctly.
2121
before: ["*sql1", "*sql2", "CREATE TABLE t3(v3 int);"]
22-
test:
22+
tasks:
2323
- logical
2424
- physical
2525
```
@@ -34,7 +34,7 @@ Basically, it is like:
3434
- "*test_case_1" # use *id to reference to another test case
3535
- "*test_case_2"
3636
- CREATE TABLE t2(v2 int); # or directly write a SQL here
37-
test: # run logical and physical test for this case
37+
tasks: # run logical and physical test for this case
3838
- logical
3939
- physical
4040
```

naivedb/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ edition = "2021"
55
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
66

77
[dependencies]
8+
anyhow = { version = "1", features = ["backtrace"] }
89
async-trait = "0.1"
910
sqlplannertest = { path = ".." }
10-
anyhow = "1"
1111
tokio = { version = "1", features = ["rt", "rt-multi-thread", "macros", "fs"] }
1212

1313
[[test]]

naivedb/src/lib.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use anyhow::Result;
1+
use anyhow::{anyhow, Result};
22
use async_trait::async_trait;
33

44
#[derive(Default)]
@@ -12,7 +12,25 @@ impl NaiveDb {
1212

1313
#[async_trait]
1414
impl sqlplannertest::PlannerTestRunner for NaiveDb {
15-
async fn run(&mut self, _test_case: &sqlplannertest::ParsedTestCase) -> Result<String> {
16-
Ok("hello, world!".to_string())
15+
async fn run(&mut self, test_case: &sqlplannertest::ParsedTestCase) -> Result<String> {
16+
use std::fmt::Write;
17+
let mut result = String::new();
18+
let r = &mut result;
19+
for task in &test_case.tasks {
20+
writeln!(r, "=== {}", task)?;
21+
writeln!(r, "I'm a naive db, so I don't now how to process")?;
22+
for before in &test_case.before_sql {
23+
writeln!(r, "{}", before)?;
24+
}
25+
writeln!(r, "{}", test_case.sql)?;
26+
writeln!(r)?;
27+
}
28+
if test_case.sql.contains("ERROR") {
29+
return Err(anyhow!("Ooops, error!"));
30+
}
31+
if test_case.sql.contains("PANIC") {
32+
panic!("I'm panic!");
33+
}
34+
Ok(result)
1735
}
1836
}

naivedb/tests/1.sql

Lines changed: 0 additions & 15 deletions
This file was deleted.

naivedb/tests/2.sql

Lines changed: 0 additions & 15 deletions
This file was deleted.

naivedb/tests/2.yml

Lines changed: 0 additions & 13 deletions
This file was deleted.

naivedb/tests/_panic.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
- sql: |
2+
PANIC
3+
desc: Test whether panic works
4+
tasks:
5+
- logical
6+
- physical

naivedb/tests/error.planner.sql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-- Test whether error works
2+
ERROR
3+
4+
/*
5+
Error
6+
Ooops, error!
7+
*/
8+

naivedb/tests/error.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
- sql: |
2+
ERROR
3+
desc: Test whether error works
4+
tasks:
5+
- logical
6+
- physical

0 commit comments

Comments
 (0)