Skip to content

Commit

Permalink
test: add integration tests for message size limit
Browse files Browse the repository at this point in the history
  • Loading branch information
TheWaWaR committed Sep 21, 2023
1 parent aef6192 commit 9fa234b
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 4 deletions.
16 changes: 13 additions & 3 deletions tests-integration/src/test_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use object_store::test_util::TempFolder;
use object_store::ObjectStore;
use secrecy::ExposeSecret;
use servers::grpc::greptime_handler::GreptimeRequestHandler;
use servers::grpc::GrpcServer;
use servers::grpc::{GrpcServer, GrpcServerConfig};
use servers::http::{HttpOptions, HttpServerBuilder};
use servers::metrics_handler::MetricsHandler;
use servers::mysql::server::{MysqlServer, MysqlSpawnConfig, MysqlSpawnRef};
Expand Down Expand Up @@ -423,13 +423,22 @@ pub async fn setup_grpc_server(
store_type: StorageType,
name: &str,
) -> (String, TestGuard, Arc<GrpcServer>) {
setup_grpc_server_with_user_provider(store_type, name, None).await
setup_grpc_server_with(store_type, name, None, None).await
}

pub async fn setup_grpc_server_with_user_provider(
store_type: StorageType,
name: &str,
user_provider: Option<UserProviderRef>,
) -> (String, TestGuard, Arc<GrpcServer>) {
setup_grpc_server_with(store_type, name, user_provider, None).await
}

pub async fn setup_grpc_server_with(
store_type: StorageType,
name: &str,
user_provider: Option<UserProviderRef>,
grpc_config: Option<GrpcServerConfig>,
) -> (String, TestGuard, Arc<GrpcServer>) {
let instance = setup_standalone_instance(name, store_type).await;

Expand All @@ -447,8 +456,9 @@ pub async fn setup_grpc_server_with_user_provider(
user_provider.clone(),
runtime.clone(),
));

let fe_grpc_server = Arc::new(GrpcServer::new(
None,
grpc_config,
Some(ServerGrpcQueryHandlerAdaptor::arc(fe_instance_ref.clone())),
Some(fe_instance_ref.clone()),
Some(flight_handler),
Expand Down
70 changes: 69 additions & 1 deletion tests-integration/tests/grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ use client::{Client, Database, DEFAULT_CATALOG_NAME, DEFAULT_SCHEMA_NAME};
use common_catalog::consts::{MIN_USER_TABLE_ID, MITO_ENGINE};
use common_query::Output;
use common_recordbatch::RecordBatches;
use servers::grpc::GrpcServerConfig;
use servers::http::prometheus::{PromData, PromSeries, PrometheusJsonResponse, PrometheusResponse};
use servers::server::Server;
use tests_integration::test_util::{
setup_grpc_server, setup_grpc_server_with_user_provider, StorageType,
setup_grpc_server, setup_grpc_server_with, setup_grpc_server_with_user_provider, StorageType,
};

#[macro_export]
Expand Down Expand Up @@ -64,6 +65,9 @@ macro_rules! grpc_tests {
test_auto_create_table,
test_insert_and_select,
test_dbname,
test_grpc_message_size_ok,
test_grpc_message_size_limit_recv,
test_grpc_message_size_limit_send,
test_grpc_auth,
test_health_check,
test_prom_gateway_query,
Expand Down Expand Up @@ -115,6 +119,70 @@ pub async fn test_dbname(store_type: StorageType) {
guard.remove_all().await;
}

pub async fn test_grpc_message_size_ok(store_type: StorageType) {
let config = GrpcServerConfig {
max_recv_message_size: 1024,
max_send_message_size: 1024,
};
let (addr, mut guard, fe_grpc_server) =
setup_grpc_server_with(store_type, "auto_create_table", None, Some(config)).await;

let grpc_client = Client::with_urls(vec![addr]);
let db = Database::new_with_dbname(
format!("{}-{}", DEFAULT_CATALOG_NAME, DEFAULT_SCHEMA_NAME),
grpc_client,
);
db.sql("show tables;").await.unwrap();
let _ = fe_grpc_server.shutdown().await;
guard.remove_all().await;
}

pub async fn test_grpc_message_size_limit_send(store_type: StorageType) {
let config = GrpcServerConfig {
max_recv_message_size: 1024,
max_send_message_size: 50,
};
let (addr, mut guard, fe_grpc_server) =
setup_grpc_server_with(store_type, "auto_create_table", None, Some(config)).await;

let grpc_client = Client::with_urls(vec![addr]);
let db = Database::new_with_dbname(
format!("{}-{}", DEFAULT_CATALOG_NAME, DEFAULT_SCHEMA_NAME),
grpc_client,
);
assert!(db
.sql("show tables;")
.await
.unwrap_err()
.to_string()
.contains("message length too large"));
let _ = fe_grpc_server.shutdown().await;
guard.remove_all().await;
}

pub async fn test_grpc_message_size_limit_recv(store_type: StorageType) {
let config = GrpcServerConfig {
max_recv_message_size: 10,
max_send_message_size: 1024,
};
let (addr, mut guard, fe_grpc_server) =
setup_grpc_server_with(store_type, "auto_create_table", None, Some(config)).await;

let grpc_client = Client::with_urls(vec![addr]);
let db = Database::new_with_dbname(
format!("{}-{}", DEFAULT_CATALOG_NAME, DEFAULT_SCHEMA_NAME),
grpc_client,
);
assert!(db
.sql("show tables;")
.await
.unwrap_err()
.to_string()
.contains("message length too large"));
let _ = fe_grpc_server.shutdown().await;
guard.remove_all().await;
}

pub async fn test_grpc_auth(store_type: StorageType) {
let user_provider = user_provider_from_option(
&"static_user_provider:cmd:greptime_user=greptime_pwd".to_string(),
Expand Down

0 comments on commit 9fa234b

Please sign in to comment.