mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-08-12 09:19:44 +00:00
feat: reduce unit test suite wall time (#7657)
* feat: reduce wait timt of from 57s to 0.6s Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * , , , Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * test_query_concurrently Signed-off-by: Ruihang Xia <waynestxia@gmail.com> --------- Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
This commit is contained in:
@@ -207,6 +207,10 @@ mod tests {
|
||||
let mut requests = request.into_inner();
|
||||
let suspend = self.suspend.clone();
|
||||
async move {
|
||||
// Make the heartbeat interval short in unit tests to reduce the waiting time.
|
||||
// Only the handshake response needs to populate it (as metasrv does).
|
||||
let heartbeat_interval_ms = Duration::from_millis(200).as_millis() as u64;
|
||||
let mut is_handshake = true;
|
||||
while let Some(request) = requests.next().await {
|
||||
if let Err(e) = request {
|
||||
let _ = tx.send(Err(e)).await;
|
||||
@@ -220,9 +224,16 @@ mod tests {
|
||||
)),
|
||||
..Default::default()
|
||||
});
|
||||
let heartbeat_config =
|
||||
is_handshake.then_some(api::v1::meta::HeartbeatConfig {
|
||||
heartbeat_interval_ms,
|
||||
retry_interval_ms: heartbeat_interval_ms,
|
||||
});
|
||||
is_handshake = false;
|
||||
let response = HeartbeatResponse {
|
||||
header: Some(ResponseHeader::success()),
|
||||
mailbox_message,
|
||||
heartbeat_config,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
@@ -376,6 +387,21 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
async fn wait_for_suspend_state(frontend: &Frontend, expected: bool) {
|
||||
let check = || frontend.instance.is_suspended() == expected;
|
||||
if check() {
|
||||
return;
|
||||
}
|
||||
|
||||
tokio::time::timeout(Duration::from_secs(5), async move {
|
||||
while !check() {
|
||||
tokio::time::sleep(Duration::from_millis(20)).await;
|
||||
}
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
|
||||
async fn test_suspend_frontend() -> Result<()> {
|
||||
common_telemetry::init_default_ut_logging();
|
||||
@@ -412,12 +438,6 @@ mod tests {
|
||||
let meta_client = create_meta_client(&meta_client_options, server.clone()).await;
|
||||
let frontend = create_frontend(&options, meta_client).await?;
|
||||
|
||||
use common_meta::distributed_time_constants::{
|
||||
BASE_HEARTBEAT_INTERVAL, frontend_heartbeat_interval,
|
||||
};
|
||||
let frontend_heartbeat_interval =
|
||||
frontend_heartbeat_interval(BASE_HEARTBEAT_INTERVAL) + Duration::from_secs(1);
|
||||
tokio::time::sleep(frontend_heartbeat_interval).await;
|
||||
// initial state: not suspend:
|
||||
assert!(!frontend.instance.is_suspended());
|
||||
verify_suspend_state_by_http(&frontend, Ok(r#"[{"records":{"schema":{"column_schemas":[{"name":"Int64(1)","data_type":"Int64"}]},"rows":[[1]],"total_rows":1}}]"#)).await;
|
||||
@@ -434,7 +454,7 @@ mod tests {
|
||||
|
||||
// make heartbeat server returned "suspend" instruction,
|
||||
server.suspend.store(true, Ordering::Relaxed);
|
||||
tokio::time::sleep(frontend_heartbeat_interval).await;
|
||||
wait_for_suspend_state(&frontend, true).await;
|
||||
// ... then the frontend is suspended:
|
||||
assert!(frontend.instance.is_suspended());
|
||||
verify_suspend_state_by_http(
|
||||
@@ -450,7 +470,7 @@ mod tests {
|
||||
|
||||
// make heartbeat server NOT returned "suspend" instruction,
|
||||
server.suspend.store(false, Ordering::Relaxed);
|
||||
tokio::time::sleep(frontend_heartbeat_interval).await;
|
||||
wait_for_suspend_state(&frontend, false).await;
|
||||
// ... then frontend's suspend state is cleared:
|
||||
assert!(!frontend.instance.is_suspended());
|
||||
verify_suspend_state_by_http(&frontend, Ok(r#"[{"records":{"schema":{"column_schemas":[{"name":"Int64(1)","data_type":"Int64"}]},"rows":[[1]],"total_rows":1}}]"#)).await;
|
||||
|
||||
Reference in New Issue
Block a user