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:
Ruihang Xia
2026-02-03 21:32:11 +08:00
committed by GitHub
parent 969a64d483
commit 0f2f20d4b7
7 changed files with 391 additions and 116 deletions
+28 -8
View File
@@ -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;