Skip to content

Commit

Permalink
feat: simple version switch
Browse files Browse the repository at this point in the history
  • Loading branch information
discord9 committed Dec 9, 2024
1 parent 903da8f commit bad3373
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/runner/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ use tokio::sync::Mutex as TokioMutex;
use tokio_postgres::{Client as PgClient, SimpleQueryMessage as PgRow};

use crate::protocol_interceptor::{MYSQL, PROTOCOL_KEY};
use crate::util::get_workspace_root;
use crate::{util, ServerAddr};

const METASRV_ADDR: &str = "127.0.0.1:29302";
Expand Down Expand Up @@ -693,8 +694,22 @@ impl GreptimeDB {
impl Database for GreptimeDB {
async fn query(&self, ctx: QueryContext, query: String) -> Box<dyn Display> {
if ctx.context.contains_key("restart") && self.env.server_addrs.server_addr.is_none() {
self.env.restart_server(self).await;
} else if let Some(version) = ctx.context.get("version") {
if version == "latest" {
// use default latest by building db now
*self.env.bins_dir.lock().unwrap() = Some(util::get_binary_dir("debug"));
} else {
// use version in dir files
let root = get_workspace_root();
let new_path = PathBuf::from_iter([&root, version]);
println!("DEBUG: {:?}", new_path);
*self.env.bins_dir.lock().unwrap() = Some(new_path);
}

self.env.restart_server(self).await;
}

if let Some(protocol) = ctx.context.get(PROTOCOL_KEY) {
// protocol is bound to be either "mysql" or "postgres"
if protocol == MYSQL {
Expand Down
1 change: 1 addition & 0 deletions tests/runner/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ async fn main() {
args.bins_dir,
),
);
println!("Working directory: {:?}", std::env::current_dir());
runner.run().await.unwrap();

// clean up and exit
Expand Down
43 changes: 43 additions & 0 deletions tests/upgrade-compat/standalone/test_simple.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
-- SQLNESS ARG version=v0.9.5
CREATE TABLE system_metrics (
host STRING,
idc STRING,
cpu_util DOUBLE,
memory_util DOUBLE,
disk_util DOUBLE,
ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
PRIMARY KEY(host, idc),
TIME INDEX(ts)
);

Affected Rows: 0

INSERT INTO system_metrics
VALUES
("host1", "idc_a", 11.8, 10.3, 10.3, 1667446797450),
("host2", "idc_a", 80.0, 70.3, 90.0, 1667446797450),
("host1", "idc_b", 50.0, 66.7, 40.6, 1667446797450);

Affected Rows: 3

-- SQLNESS ARG version=latest
SHOW CREATE TABLE system_metrics;

+----------------+-----------------------------------------------------------+
| Table | Create Table |
+----------------+-----------------------------------------------------------+
| system_metrics | CREATE TABLE IF NOT EXISTS "system_metrics" ( |
| | "host" STRING NULL, |
| | "idc" STRING NULL, |
| | "cpu_util" DOUBLE NULL, |
| | "memory_util" DOUBLE NULL, |
| | "disk_util" DOUBLE NULL, |
| | "ts" TIMESTAMP(3) NOT NULL DEFAULT current_timestamp(), |
| | TIME INDEX ("ts"), |
| | PRIMARY KEY ("host", "idc") |
| | ) |
| | |
| | ENGINE=mito |
| | |
+----------------+-----------------------------------------------------------+

20 changes: 20 additions & 0 deletions tests/upgrade-compat/standalone/test_simple.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-- SQLNESS ARG version=v0.9.5
CREATE TABLE system_metrics (
host STRING,
idc STRING,
cpu_util DOUBLE,
memory_util DOUBLE,
disk_util DOUBLE,
ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
PRIMARY KEY(host, idc),
TIME INDEX(ts)
);

INSERT INTO system_metrics
VALUES
("host1", "idc_a", 11.8, 10.3, 10.3, 1667446797450),
("host2", "idc_a", 80.0, 70.3, 90.0, 1667446797450),
("host1", "idc_b", 50.0, 66.7, 40.6, 1667446797450);

-- SQLNESS ARG version=latest
SHOW CREATE TABLE system_metrics;

0 comments on commit bad3373

Please sign in to comment.