Remove `testsuite` crate and decompose a few tests

next
Sayan Nandan 4 years ago
parent 425afbe8c7
commit 5d499fa36d
No known key found for this signature in database
GPG Key ID: C31EFD7DDA12AEE0

7
Cargo.lock generated

@ -641,13 +641,6 @@ dependencies = [
"winapi-util",
]
[[package]]
name = "testsuite"
version = "0.1.0"
dependencies = [
"tdb_macros",
]
[[package]]
name = "textwrap"
version = "0.11.0"

@ -4,8 +4,7 @@ members = [
"server",
"libtdb",
"tdb-bench",
"tdb-macros",
"testsuite"
"tdb-macros"
]
[profile.release]

@ -20,8 +20,7 @@
*/
#[tdb_macros::dbtest(skip = "set_values")]
mod tests {
mod __private {
/// Test a HEYA query: The server should return HEY!
async fn test_heya() {
let heya = terrapipe::proc_query("HEYA");
@ -58,22 +57,12 @@ mod tests {
stream.write_all(&syntax_error).await.unwrap();
let mut response = vec![0; fresp::R_ACTION_ERR.len()];
stream.read_exact(&mut response).await.unwrap();
assert_eq!(
response,
fresp::R_ACTION_ERR.to_owned(),
"{}: With zero arg(s)",
__func__!()
);
assert_eq!(response, fresp::R_ACTION_ERR.to_owned(), "With zero arg(s)");
let syntax_error = terrapipe::proc_query("GET one two");
stream.write_all(&syntax_error).await.unwrap();
let mut response = vec![0; fresp::R_ACTION_ERR.len()];
stream.read_exact(&mut response).await.unwrap();
assert_eq!(
response,
fresp::R_ACTION_ERR.to_owned(),
"{}: With two arg(s)",
__func__!()
);
assert_eq!(response, fresp::R_ACTION_ERR.to_owned(), "With two arg(s)");
}
/// Set a couple of values, which are to be passed as a list of whitespace separated values
@ -86,12 +75,9 @@ mod tests {
values_split_with_whitespace: T,
homwany: usize,
stream: &mut tokio::net::TcpStream,
)
where
) where
T: AsRef<str>,
{
use crate::tests::{fresp, terrapipe, TcpStream};
use crate::__func__;
use tokio::prelude::*;
let mut query = String::from("MSET ");
query.push_str(values_split_with_whitespace.as_ref());
@ -121,12 +107,7 @@ mod tests {
stream.write_all(&set_single_code_2).await.unwrap();
let mut response = vec![0; fresp::R_OVERWRITE_ERR.len()];
stream.read_exact(&mut response).await.unwrap();
assert_eq!(
response,
fresp::R_OVERWRITE_ERR.to_owned(),
"{}",
__func__!()
);
assert_eq!(response, fresp::R_OVERWRITE_ERR.to_owned());
}
/// Test a SET query with incorrect number of arugments
@ -135,37 +116,22 @@ mod tests {
stream.write_all(&syntax_error).await.unwrap();
let mut response = vec![0; fresp::R_ACTION_ERR.len()];
stream.read_exact(&mut response).await.unwrap();
assert_eq!(
response,
fresp::R_ACTION_ERR.to_owned(),
"{}: With zero arg(s)",
__func__!()
);
assert_eq!(response, fresp::R_ACTION_ERR.to_owned(), "With zero arg(s)",);
let syntax_error = terrapipe::proc_query("SET one");
stream.write_all(&syntax_error).await.unwrap();
let mut response = vec![0; fresp::R_ACTION_ERR.len()];
stream.read_exact(&mut response).await.unwrap();
assert_eq!(
response,
fresp::R_ACTION_ERR.to_owned(),
"{}: With one arg(s)",
__func__!()
);
assert_eq!(response, fresp::R_ACTION_ERR.to_owned(), "With one arg(s)",);
let syntax_error = terrapipe::proc_query("SET one 1 two 2");
stream.write_all(&syntax_error).await.unwrap();
let mut response = vec![0; fresp::R_ACTION_ERR.len()];
stream.read_exact(&mut response).await.unwrap();
assert_eq!(
response,
fresp::R_ACTION_ERR.to_owned(),
"{}: With four arg(s)",
__func__!()
);
assert_eq!(response, fresp::R_ACTION_ERR.to_owned(), "With four arg(s)",);
}
/// Test an UPDATE query: which should return code: 0
async fn test_update_single_okay() {
set_values("x 100", 1, &mut stream).await;;
set_values("x 100", 1, &mut stream).await;
let update_single_okay = terrapipe::proc_query("UPDATE x 200");
stream.write_all(&update_single_okay).await.unwrap();
let mut response = vec![0; fresp::R_OKAY.len()];
@ -187,32 +153,17 @@ mod tests {
stream.write_all(&syntax_error).await.unwrap();
let mut response = vec![0; fresp::R_ACTION_ERR.len()];
stream.read_exact(&mut response).await.unwrap();
assert_eq!(
response,
fresp::R_ACTION_ERR.to_owned(),
"{}: With zero arg(s)",
__func__!()
);
assert_eq!(response, fresp::R_ACTION_ERR.to_owned(), "With zero arg(s)",);
let syntax_error = terrapipe::proc_query("UPDATE one");
stream.write_all(&syntax_error).await.unwrap();
let mut response = vec![0; fresp::R_ACTION_ERR.len()];
stream.read_exact(&mut response).await.unwrap();
assert_eq!(
response,
fresp::R_ACTION_ERR.to_owned(),
"{}: With one arg(s)",
__func__!()
);
assert_eq!(response, fresp::R_ACTION_ERR.to_owned(), "With one arg(s)",);
let syntax_error = terrapipe::proc_query("UPDATE one 1 two 2");
stream.write_all(&syntax_error).await.unwrap();
let mut response = vec![0; fresp::R_ACTION_ERR.len()];
stream.read_exact(&mut response).await.unwrap();
assert_eq!(
response,
fresp::R_ACTION_ERR.to_owned(),
"{}: With four arg(s)",
__func__!()
);
assert_eq!(response, fresp::R_ACTION_ERR.to_owned(), "With four arg(s)",);
}
/// Test a DEL query: which should return int 0
@ -270,12 +221,7 @@ mod tests {
let res_should_be = "#2\n*1\n#2\n&1\n:1\n3\n".to_owned().into_bytes();
let mut response = vec![0; res_should_be.len()];
stream.read_exact(&mut response).await.unwrap();
assert_eq!(
response,
res_should_be,
"{}: With three arg(s)",
__func__!()
);
assert_eq!(response, res_should_be, "With three arg(s)",);
}
/// Test an EXISTS query with an incorrect number of arguments
@ -361,49 +307,30 @@ mod tests {
let res_should_be = "#2\n*1\n#2\n&1\n:1\n2\n".to_owned().into_bytes();
let mut response = vec![0; res_should_be.len()];
stream.read_exact(&mut response).await.unwrap();
assert_eq!(
response,
res_should_be,
"{}: With 3 k/v pair(s)",
__func__!()
);
assert_eq!(response, res_should_be, "With 3 k/v pair(s)");
// Now all the keys have been set, so we should get a 0
let query = terrapipe::proc_query("MSET x ex y why z zed");
stream.write_all(&query).await.unwrap();
let res_should_be = "#2\n*1\n#2\n&1\n:1\n0\n".to_owned().into_bytes();
let mut response = vec![0; res_should_be.len()];
stream.read_exact(&mut response).await.unwrap();
assert_eq!(
response,
res_should_be,
"{}: With 3 k/v pair(s)",
__func__!()
);
assert_eq!(response, res_should_be, "With 3 k/v pair(s)");
}
/// Test an MSET query with the wrong number of arguments
async fn test_mset_syntax_error() {
async fn test_mset_syntax_error_args_one() {
let syntax_error = terrapipe::proc_query("MSET");
stream.write_all(&syntax_error).await.unwrap();
let mut response = vec![0; fresp::R_ACTION_ERR.len()];
stream.read_exact(&mut response).await.unwrap();
assert_eq!(
response,
fresp::R_ACTION_ERR.to_owned(),
"{}: With one arg(s)",
__func__!()
);
// Now we'll test it with two keys and one-value
assert_eq!(response, fresp::R_ACTION_ERR.to_owned());
}
async fn test_mset_syntax_error_args_three() {
let syntax_error = terrapipe::proc_query("MSET x ex y");
stream.write_all(&syntax_error).await.unwrap();
let mut response = vec![0; fresp::R_ACTION_ERR.len()];
stream.read_exact(&mut response).await.unwrap();
assert_eq!(
response,
fresp::R_ACTION_ERR.to_owned(),
"{}: With three arg(s)",
__func__!()
);
assert_eq!(response, fresp::R_ACTION_ERR.to_owned());
}
/// Test an MUPDATE query with a single non-existing keys
@ -425,49 +352,31 @@ mod tests {
let res_should_be = "#2\n*1\n#2\n&1\n:1\n1\n".to_owned().into_bytes();
let mut response = vec![0; res_should_be.len()];
stream.read_exact(&mut response).await.unwrap();
assert_eq!(
response,
res_should_be,
"{}: With 3 k/v pair(s)",
__func__!()
);
assert_eq!(response, res_should_be, "With 3 k/v pair(s)");
// None of these keys exist, so we should get a 0
let query = terrapipe::proc_query("MUPDATE y why z zed");
stream.write_all(&query).await.unwrap();
let res_should_be = "#2\n*1\n#2\n&1\n:1\n0\n".to_owned().into_bytes();
let mut response = vec![0; res_should_be.len()];
stream.read_exact(&mut response).await.unwrap();
assert_eq!(
response,
res_should_be,
"{}: With 2 k/v pair(s)",
__func__!()
);
assert_eq!(response, res_should_be, "With 2 k/v pair(s)");
}
/// Test an MUPDATE query with the wrong number of arguments
async fn test_mupdate_syntax_error() {
async fn test_mupdate_syntax_error_args_one() {
let syntax_error = terrapipe::proc_query("MUPDATE");
stream.write_all(&syntax_error).await.unwrap();
let mut response = vec![0; fresp::R_ACTION_ERR.len()];
stream.read_exact(&mut response).await.unwrap();
assert_eq!(
response,
fresp::R_ACTION_ERR.to_owned(),
"{}: With one arg(s)",
__func__!()
);
// Now we'll test it with two keys and one-value
assert_eq!(response, fresp::R_ACTION_ERR.to_owned());
}
async fn test_mupdate_syntax_error_args_three() {
let syntax_error = terrapipe::proc_query("MUPDATE x ex y");
stream.write_all(&syntax_error).await.unwrap();
let mut response = vec![0; fresp::R_ACTION_ERR.len()];
stream.read_exact(&mut response).await.unwrap();
assert_eq!(
response,
fresp::R_ACTION_ERR.to_owned(),
"{}: With three arg(s)",
__func__!()
);
assert_eq!(response, fresp::R_ACTION_ERR.to_owned());
}
/// Test an SSET query: which should return code: 0
@ -486,12 +395,7 @@ mod tests {
stream.write_all(&sset_single_error).await.unwrap();
let mut response = vec![0; fresp::R_OVERWRITE_ERR.len()];
stream.read_exact(&mut response).await.unwrap();
assert_eq!(
response,
fresp::R_OVERWRITE_ERR.to_owned(),
"{}",
__func__!()
);
assert_eq!(response, fresp::R_OVERWRITE_ERR.to_owned());
}
/// Test an SSET query: which should return code: 0
@ -510,37 +414,24 @@ mod tests {
stream.write_all(&update_single_okay).await.unwrap();
let mut response = vec![0; fresp::R_OVERWRITE_ERR.len()];
stream.read_exact(&mut response).await.unwrap();
assert_eq!(
response,
fresp::R_OVERWRITE_ERR.to_owned(),
"{}",
__func__!()
);
assert_eq!(response, fresp::R_OVERWRITE_ERR.to_owned());
}
/// Test an SSET query with the wrong number of arguments
async fn test_sset_syntax_error() {
async fn test_sset_syntax_error_args_one() {
let syntax_error = terrapipe::proc_query("SSET");
stream.write_all(&syntax_error).await.unwrap();
let mut response = vec![0; fresp::R_ACTION_ERR.len()];
stream.read_exact(&mut response).await.unwrap();
assert_eq!(
response,
fresp::R_ACTION_ERR.to_owned(),
"{}: With one arg(s)",
__func__!()
);
// Now we'll test it with two keys and one-value
assert_eq!(response, fresp::R_ACTION_ERR.to_owned());
}
async fn test_sset_syntax_error_args_three() {
let syntax_error = terrapipe::proc_query("SSET x ex y");
stream.write_all(&syntax_error).await.unwrap();
let mut response = vec![0; fresp::R_ACTION_ERR.len()];
stream.read_exact(&mut response).await.unwrap();
assert_eq!(
response,
fresp::R_ACTION_ERR.to_owned(),
"{}: With three arg(s)",
__func__!()
);
assert_eq!(response, fresp::R_ACTION_ERR.to_owned());
}
/// Test an SUPDATE query: which should return code: 0
@ -583,28 +474,20 @@ mod tests {
}
/// Test an SUPDATE query with the wrong number of arguments
async fn test_supdate_syntax_error() {
async fn test_supdate_syntax_error_args_one() {
let syntax_error = terrapipe::proc_query("SUPDATE");
stream.write_all(&syntax_error).await.unwrap();
let mut response = vec![0; fresp::R_ACTION_ERR.len()];
stream.read_exact(&mut response).await.unwrap();
assert_eq!(
response,
fresp::R_ACTION_ERR.to_owned(),
"{}: With one arg(s)",
__func__!()
);
// Now we'll test it with two keys and one-value
assert_eq!(response, fresp::R_ACTION_ERR.to_owned());
}
async fn test_supdate_syntax_error_args_two() {
let syntax_error = terrapipe::proc_query("SUPDATE x ex y");
stream.write_all(&syntax_error).await.unwrap();
let mut response = vec![0; fresp::R_ACTION_ERR.len()];
stream.read_exact(&mut response).await.unwrap();
assert_eq!(
response,
fresp::R_ACTION_ERR.to_owned(),
"{}: With three arg(s)",
__func__!()
);
assert_eq!(response, fresp::R_ACTION_ERR.to_owned());
}
/// Test an SDEL query: which should return nil
@ -724,29 +607,20 @@ mod tests {
}
/// Test `USET` with an incorrect number of arguments
async fn test_uset_syntax_error() {
async fn test_uset_syntax_error_args_one() {
let query = terrapipe::proc_query("USET");
let query2 = terrapipe::proc_query("USET x");
let mut resp1 = vec![0; fresp::R_ACTION_ERR.len()];
let mut resp2 = vec![0; fresp::R_ACTION_ERR.len()];
stream.write_all(&query).await.unwrap();
stream.read_exact(&mut resp1).await.unwrap();
assert_eq!(resp1, fresp::R_ACTION_ERR.to_owned());
}
async fn test_uset_syntax_error_args_two() {
let mut resp2 = vec![0; fresp::R_ACTION_ERR.len()];
let query2 = terrapipe::proc_query("USET x");
stream.write_all(&query2).await.unwrap();
stream.read_exact(&mut resp2).await.unwrap();
assert_eq!(
resp1,
fresp::R_ACTION_ERR.to_owned(),
"{}:{}",
__func__!(),
"with one arg"
);
assert_eq!(
resp2,
fresp::R_ACTION_ERR.to_owned(),
"{}:{}",
__func__!(),
"with two args"
);
assert_eq!(resp2, fresp::R_ACTION_ERR.to_owned(),);
}
/// Test `KEYLEN`
@ -761,28 +635,18 @@ mod tests {
}
/// Test `KEYLEN` with an incorrect number of arguments
async fn test_keylen_syntax_error() {
async fn test_keylen_syntax_error_args_one() {
let query = terrapipe::proc_query("KEYLEN");
stream.write_all(&query).await.unwrap();
let mut response = vec![0; fresp::R_ACTION_ERR.len()];
stream.read_exact(&mut response).await.unwrap();
assert_eq!(
response,
fresp::R_ACTION_ERR.to_owned(),
"{}:{}",
__func__!(),
"with 1 arg(s)"
);
assert_eq!(response, fresp::R_ACTION_ERR.to_owned());
}
async fn test_keylen_syntax_error_args_two() {
let query = terrapipe::proc_query("KEYLEN x y");
stream.write_all(&query).await.unwrap();
let mut response = vec![0; fresp::R_ACTION_ERR.len()];
stream.read_exact(&mut response).await.unwrap();
assert_eq!(
response,
fresp::R_ACTION_ERR.to_owned(),
"{}:{}",
__func__!(),
"with 2 arg(s)"
);
assert_eq!(response, fresp::R_ACTION_ERR.to_owned());
}
}

@ -27,8 +27,7 @@ use crate::dbnet;
use crate::protocol::responses::fresp;
use crate::BGSave;
use libtdb::terrapipe;
use std::net::{Shutdown, SocketAddr};
use std::{future::Future, sync::Arc};
use std::net::{SocketAddr};
use tokio::net::{TcpListener, TcpStream};
mod kvengine;

@ -142,10 +142,17 @@ fn parse_test_module(args: TokenStream, item: TokenStream) -> TokenStream {
_ => (),
}
}
let attrs = &input.attrs;
let vis = &input.vis;
let mod_token = &input.mod_token;
let modname = &input.ident;
if modname.to_string() != "__private" {
return syn::Error::new_spanned(
modname,
"By convention, all the modules using the `dbtest` macro have to be called `__private`",
)
.to_compile_error()
.into();
}
let mut rng = thread_rng();
let mut in_set = HashSet::<u16>::new();

@ -1,10 +0,0 @@
[package]
name = "testsuite"
version = "0.1.0"
authors = ["Sayan Nandan <ohsayan@outlook.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
tdb_macros = {path="../tdb-macros"}

@ -1,27 +0,0 @@
/*
* Created on Mon Sep 14 2020
*
* This file is a part of TerrabaseDB
* Copyright (c) 2020, Sayan Nandan <ohsayan at outlook dot com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
//! TerrabaseDB's testing suite
//!
//! This crate contains modules which are used for testing TerrabaseDB
pub mod service;
pub use tdb_macros;

@ -1,56 +0,0 @@
/*
* Created on Sun Sep 13 2020
*
* This file is a part of TerrabaseDB
* Copyright (c) 2020, Sayan Nandan <ohsayan at outlook dot com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
//! Objects for handling background services
//!
use std::path;
use std::process;
/// A `BackgroundTask` starts `tdb` in a background task
pub struct BackGroundTask {
child: process::Child,
}
impl BackGroundTask {
/// Start a new background database server
///
/// **Note**: This function expects that you're running it from the workspace
/// root. It is **test-only**, and this must be kept in mind.
pub fn new() -> Self {
if !path::Path::new("../target/debug/tdb").exists() {
panic!("The `tdb` binary could not be found");
}
let cmd = process::Command::new("../target/debug/tdb")
.spawn()
.unwrap();
BackGroundTask { child: cmd }
}
/// Execute a function block
pub fn execute(&self, body: fn() -> ()) {
body()
}
}
impl Drop for BackGroundTask {
fn drop(&mut self) {
// Terminate the background server
self.child.kill().unwrap();
}
}
Loading…
Cancel
Save