Skip to content

Commit 9a30ba0

Browse files
authored
test: run sqlness test in distributed mode (#916)
* test: run sqlness test in distributed mode * chore: fix ci test * chore: improve the ci yaml * chore: improve the code * chore: fix conflicts
1 parent 8149932 commit 9a30ba0

File tree

7 files changed

+281
-3
lines changed

7 files changed

+281
-3
lines changed

.github/workflows/develop.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,17 @@ jobs:
126126
toolchain: ${{ env.RUST_TOOLCHAIN }}
127127
- name: Rust Cache
128128
uses: Swatinem/rust-cache@v2
129+
- name: Run etcd
130+
run: |
131+
ETCD_VER=v3.5.7
132+
DOWNLOAD_URL=https://github.com/etcd-io/etcd/releases/download
133+
curl -L ${DOWNLOAD_URL}/${ETCD_VER}/etcd-${ETCD_VER}-linux-amd64.tar.gz -o /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz
134+
mkdir -p /tmp/etcd-download
135+
tar xzvf /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz -C /tmp/etcd-download --strip-components=1
136+
rm -f /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz
137+
138+
sudo cp -a /tmp/etcd-download/etcd* /usr/local/bin/
139+
nohup etcd >/tmp/etcd.log 2>&1 &
129140
- name: Run sqlness
130141
run: cargo run --bin sqlness-runner && ls /tmp
131142
- name: Upload sqlness logs

.github/workflows/release.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,25 @@ jobs:
6969
run: |
7070
brew install protobuf
7171
72+
- name: Install etcd for linux
73+
if: contains(matrix.arch, 'linux') && endsWith(matrix.arch, '-gnu')
74+
run: |
75+
ETCD_VER=v3.5.7
76+
DOWNLOAD_URL=https://github.com/etcd-io/etcd/releases/download
77+
curl -L ${DOWNLOAD_URL}/${ETCD_VER}/etcd-${ETCD_VER}-linux-amd64.tar.gz -o /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz
78+
mkdir -p /tmp/etcd-download
79+
tar xzvf /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz -C /tmp/etcd-download --strip-components=1
80+
rm -f /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz
81+
82+
sudo cp -a /tmp/etcd-download/etcd* /usr/local/bin/
83+
nohup etcd >/tmp/etcd.log 2>&1 &
84+
85+
- name: Install etcd for macos
86+
if: contains(matrix.arch, 'darwin')
87+
run: |
88+
brew install etcd
89+
brew services start etcd
90+
7291
- name: Install dependencies for linux
7392
if: contains(matrix.arch, 'linux') && endsWith(matrix.arch, '-gnu')
7493
run: |
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
SELECT 2*3+1;
2+
3+
+--------------------------------+
4+
| Int64(2) * Int64(3) + Int64(1) |
5+
+--------------------------------+
6+
| 7 |
7+
+--------------------------------+
8+
9+
SELECT 1+2*3;
10+
11+
+--------------------------------+
12+
| Int64(1) + Int64(2) * Int64(3) |
13+
+--------------------------------+
14+
| 7 |
15+
+--------------------------------+
16+
17+
SELECT 2^2 + 1;
18+
19+
+--------------------------------+
20+
| Int64(2) # Int64(2) + Int64(1) |
21+
+--------------------------------+
22+
| 1 |
23+
+--------------------------------+
24+
25+
SELECT 1+2^2;
26+
27+
+--------------------------------+
28+
| Int64(1) + Int64(2) # Int64(2) |
29+
+--------------------------------+
30+
| 1 |
31+
+--------------------------------+
32+
33+
SELECT 2*4 / 2;
34+
35+
+--------------------------------+
36+
| Int64(2) * Int64(4) / Int64(2) |
37+
+--------------------------------+
38+
| 4 |
39+
+--------------------------------+
40+
41+
SELECT 2*(4 / 2);
42+
43+
+--------------------------------+
44+
| Int64(2) * Int64(4) / Int64(2) |
45+
+--------------------------------+
46+
| 4 |
47+
+--------------------------------+
48+
49+
SELECT 16/2*4;
50+
51+
+---------------------------------+
52+
| Int64(16) / Int64(2) * Int64(4) |
53+
+---------------------------------+
54+
| 32 |
55+
+---------------------------------+
56+
57+
SELECT (16/2)*4;
58+
59+
+---------------------------------+
60+
| Int64(16) / Int64(2) * Int64(4) |
61+
+---------------------------------+
62+
| 32 |
63+
+---------------------------------+
64+
65+
SELECT 2*3*2;
66+
67+
+--------------------------------+
68+
| Int64(2) * Int64(3) * Int64(2) |
69+
+--------------------------------+
70+
| 12 |
71+
+--------------------------------+
72+
73+
SELECT 2^3*2;
74+
75+
+--------------------------------+
76+
| Int64(2) # Int64(3) * Int64(2) |
77+
+--------------------------------+
78+
| 4 |
79+
+--------------------------------+
80+
81+
SELECT 2*3^2;
82+
83+
+--------------------------------+
84+
| Int64(2) * Int64(3) # Int64(2) |
85+
+--------------------------------+
86+
| 4 |
87+
+--------------------------------+
88+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
SELECT 2*3+1;
2+
3+
SELECT 1+2*3;
4+
5+
SELECT 2^2 + 1;
6+
7+
SELECT 1+2^2;
8+
9+
SELECT 2*4 / 2;
10+
11+
SELECT 2*(4 / 2);
12+
13+
SELECT 16/2*4;
14+
15+
SELECT (16/2)*4;
16+
17+
SELECT 2*3*2;
18+
19+
SELECT 2^3*2;
20+
21+
SELECT 2*3^2;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
select 1;
2+
3+
+----------+
4+
| Int64(1) |
5+
+----------+
6+
| 1 |
7+
+----------+
8+
9+
select 2 + 3;
10+
11+
+---------------------+
12+
| Int64(2) + Int64(3) |
13+
+---------------------+
14+
| 5 |
15+
+---------------------+
16+
17+
select 4 + 0.5;
18+
19+
+-------------------------+
20+
| Int64(4) + Float64(0.5) |
21+
+-------------------------+
22+
| 4.5 |
23+
+-------------------------+
24+
25+
select "a";
26+
27+
Error: 3000(PlanQuery), Schema error: No field named 'a'. Valid fields are .
28+
29+
select "A";
30+
31+
Error: 3000(PlanQuery), Schema error: No field named 'A'. Valid fields are .
32+
33+
select * where "a" = "A";
34+
35+
Error: 3000(PlanQuery), Schema error: No field named 'a'. Valid fields are .
36+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
select 1;
2+
3+
select 2 + 3;
4+
5+
select 4 + 0.5;
6+
7+
select "a";
8+
9+
select "A";
10+
11+
select * where "a" = "A";

tests/runner/src/env.rs

Lines changed: 95 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,13 @@ use tokio::process::{Child, Command};
2828

2929
use crate::util;
3030

31+
const DATANODE_ADDR: &str = "127.0.0.1:4100";
32+
const METASRV_ADDR: &str = "127.0.0.1:3002";
3133
const SERVER_ADDR: &str = "127.0.0.1:4001";
3234
const SERVER_LOG_FILE: &str = "/tmp/greptime-sqlness.log";
35+
const METASRV_LOG_FILE: &str = "/tmp/greptime-sqlness-metasrv.log";
36+
const FRONTEND_LOG_FILE: &str = "/tmp/greptime-sqlness-frontend.log";
37+
const DATANODE_LOG_FILE: &str = "/tmp/greptime-sqlness-datanode.log";
3338

3439
pub struct Env {}
3540

@@ -48,8 +53,14 @@ impl EnvController for Env {
4853
/// Stop one [`Database`].
4954
#[allow(clippy::print_stdout)]
5055
async fn stop(&self, _mode: &str, mut database: Self::DB) {
51-
database.server_process.kill().await.unwrap();
52-
let _ = database.server_process.wait().await;
56+
let mut server = database.server_process;
57+
Env::stop_server(&mut server).await;
58+
if let Some(mut metasrv) = database.metasrv_process.take() {
59+
Env::stop_server(&mut metasrv).await;
60+
}
61+
if let Some(mut datanode) = database.datanode_process.take() {
62+
Env::stop_server(&mut datanode).await;
63+
}
5364
println!("Stopped DB.");
5465
}
5566
}
@@ -98,18 +109,99 @@ impl Env {
98109

99110
GreptimeDB {
100111
server_process,
112+
metasrv_process: None,
113+
datanode_process: None,
101114
client,
102115
db,
103116
}
104117
}
105118

106119
pub async fn start_distributed() -> GreptimeDB {
107-
todo!()
120+
let cargo_build_result = Command::new("cargo")
121+
.current_dir(util::get_workspace_root())
122+
.args(["build", "--bin", "greptime"])
123+
.stdout(Stdio::null())
124+
.output()
125+
.await
126+
.expect("Failed to start GreptimeDB")
127+
.status;
128+
if !cargo_build_result.success() {
129+
panic!("Failed to build GreptimeDB (`cargo build` fails)");
130+
}
131+
132+
// start a distributed GreptimeDB
133+
let mut meta_server = Env::start_server("metasrv");
134+
// wait for election
135+
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
136+
let mut frontend = Env::start_server("frontend");
137+
let mut datanode = Env::start_server("datanode");
138+
139+
for addr in [DATANODE_ADDR, METASRV_ADDR, SERVER_ADDR].iter() {
140+
let is_up = util::check_port(addr.parse().unwrap(), Duration::from_secs(10)).await;
141+
if !is_up {
142+
Env::stop_server(&mut meta_server).await;
143+
Env::stop_server(&mut frontend).await;
144+
Env::stop_server(&mut datanode).await;
145+
panic!("Server {addr} doesn't up in 10 seconds, quit.")
146+
}
147+
}
148+
149+
let client = Client::with_urls(vec![SERVER_ADDR]);
150+
let db = DB::new("greptime", client.clone());
151+
152+
GreptimeDB {
153+
server_process: frontend,
154+
metasrv_process: Some(meta_server),
155+
datanode_process: Some(datanode),
156+
client,
157+
db,
158+
}
159+
}
160+
161+
async fn stop_server(process: &mut Child) {
162+
process.kill().await.unwrap();
163+
let _ = process.wait().await;
164+
}
165+
166+
fn start_server(subcommand: &str) -> Child {
167+
let log_file_name = match subcommand {
168+
"datanode" => DATANODE_LOG_FILE,
169+
"frontend" => FRONTEND_LOG_FILE,
170+
"metasrv" => METASRV_LOG_FILE,
171+
_ => panic!("Unexpected subcommand: {subcommand}"),
172+
};
173+
let log_file = OpenOptions::new()
174+
.create(true)
175+
.write(true)
176+
.truncate(true)
177+
.open(log_file_name)
178+
.unwrap_or_else(|_| panic!("Cannot open log file at {log_file_name}"));
179+
180+
let mut args = vec![subcommand, "start"];
181+
if subcommand == "frontend" {
182+
args.push("--metasrv-addr=0.0.0.0:3002");
183+
} else if subcommand == "datanode" {
184+
args.push("--rpc-addr=0.0.0.0:4100");
185+
args.push("--metasrv-addr=0.0.0.0:3002");
186+
args.push("--node-id=1");
187+
args.push("--data-dir=/tmp/greptimedb_node_1/data");
188+
args.push("--wal-dir=/tmp/greptimedb_node_1/wal");
189+
}
190+
191+
let process = Command::new("./greptime")
192+
.current_dir(util::get_binary_dir("debug"))
193+
.args(args)
194+
.stdout(log_file)
195+
.spawn()
196+
.expect("Failed to start the DB");
197+
process
108198
}
109199
}
110200

111201
pub struct GreptimeDB {
112202
server_process: Child,
203+
metasrv_process: Option<Child>,
204+
datanode_process: Option<Child>,
113205
#[allow(dead_code)]
114206
client: Client,
115207
db: DB,

0 commit comments

Comments
 (0)