From 7ef762a88ef2fdd626df4f035ee759ef42b2ef0d Mon Sep 17 00:00:00 2001 From: Marco Neumann Date: Fri, 12 Nov 2021 10:38:06 +0100 Subject: [PATCH] tests: add `test_serving_readiness_router` --- .../tests/end_to_end_cases/deployment_api.rs | 46 ++++++++++++++++++- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/influxdb_iox/tests/end_to_end_cases/deployment_api.rs b/influxdb_iox/tests/end_to_end_cases/deployment_api.rs index 57b51462ef..1f05e43e1c 100644 --- a/influxdb_iox/tests/end_to_end_cases/deployment_api.rs +++ b/influxdb_iox/tests/end_to_end_cases/deployment_api.rs @@ -1,4 +1,6 @@ -use influxdb_iox_client::{management::generated_types::DatabaseRules, write::WriteError}; +use influxdb_iox_client::{ + management::generated_types::DatabaseRules, router::generated_types::Router, write::WriteError, +}; use tonic::Code; use crate::common::server_fixture::{ServerFixture, ServerType}; @@ -46,7 +48,47 @@ async fn test_serving_readiness_database() { write_client.write_lp(name, lp_data, 0).await.unwrap(); } -// TODO(marco): add `test_serving_readiness_router` once we have some other API that we could use for testing +#[tokio::test] +async fn test_serving_readiness_router() { + let server_fixture = ServerFixture::create_single_use(ServerType::Router).await; + let mut deployment_client = server_fixture.deployment_client(); + let mut router_client = server_fixture.router_client(); + let mut write_client = server_fixture.write_client(); + + let name = "foo"; + let lp_data = "bar baz=1 10"; + + deployment_client + .update_server_id(42) + .await + .expect("set ID failed"); + router_client + .update_router(Router { + name: name.to_string(), + ..Default::default() + }) + .await + .expect("create router failed"); + + assert!(deployment_client.get_serving_readiness().await.unwrap()); + + deployment_client + .set_serving_readiness(false) + .await + .unwrap(); + let err = write_client.write_lp(name, lp_data, 0).await.unwrap_err(); + assert!( + matches!(&err, WriteError::ServerError(status) if status.code() == Code::Unavailable), + "{}", + &err + ); + + assert!(!deployment_client.get_serving_readiness().await.unwrap()); + + deployment_client.set_serving_readiness(true).await.unwrap(); + assert!(deployment_client.get_serving_readiness().await.unwrap()); + write_client.write_lp(name, lp_data, 0).await.unwrap(); +} #[tokio::test] async fn test_set_get_writer_id_database() {