Skip to content

Commit 1a1e45c

Browse files
committed
fix: Address unit tests hang on multi partition
Signed-off-by: Xuanwo <github@xuanwo.io>
1 parent 91c20e3 commit 1a1e45c

File tree

4 files changed

+7
-20
lines changed

4 files changed

+7
-20
lines changed

src/common/base/src/base/singleton_instance.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl SingletonType {
5656
let guard = LOCAL.wait().read();
5757
let v: &T = guard
5858
.get(&thread_name)
59-
.unwrap_or_else(|| panic!("thread {thread_name} is not initiated"))
59+
.unwrap_or_else(|| panic!("thread {thread_name} is not initiated, don't worry if we are in dropping"))
6060
.get();
6161
v.clone()
6262
}
@@ -75,7 +75,7 @@ impl SingletonType {
7575
let guard = LOCAL.wait().read();
7676
guard
7777
.get(&thread_name)
78-
.unwrap_or_else(|| panic!("thread {thread_name} is not initiated"))
78+
.unwrap_or_else(|| panic!("thread {thread_name} is not initiated, don't worry if we are in dropping"))
7979
.set(value)
8080
}
8181
}

src/query/service/src/sessions/session_mgr.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,10 @@ impl SessionManager {
158158

159159
// stop tracking session
160160
{
161-
let mut sessions = self.active_sessions.write();
162-
sessions.remove(session_id);
161+
// Make sure this write lock has been released before dropping.
162+
// Becuase droping session could re-enter `destroy_session`.
163+
let weak_session = { self.active_sessions.write().remove(session_id) };
164+
drop(weak_session);
163165
}
164166

165167
// also need remove mysql_conn_map

src/query/service/tests/it/servers/http/http_query_handlers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1383,7 +1383,7 @@ async fn test_func_object_keys() -> Result<()> {
13831383
Ok(())
13841384
}
13851385

1386-
#[tokio::test(flavor = "current_thread")]
1386+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
13871387
async fn test_multi_partition() -> Result<()> {
13881388
let _guard = TestGlobalServices::setup(ConfigBuilder::create().build()).await?;
13891389

src/query/service/tests/it/tests/sessions.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ use common_config::Config;
1717
use common_exception::Result;
1818
use common_tracing::set_panic_hook;
1919
use databend_query::clusters::ClusterDiscovery;
20-
use databend_query::sessions::SessionManager;
2120
use databend_query::GlobalServices;
22-
use tracing::debug;
2321
use tracing::info;
2422

2523
pub struct TestGlobalServices;
@@ -64,19 +62,6 @@ pub struct TestGuard {
6462

6563
impl Drop for TestGuard {
6664
fn drop(&mut self) {
67-
// Check if session manager sill have active sessions.
68-
{
69-
let session_mgr = SessionManager::instance();
70-
// Destory all sessions.
71-
for process in session_mgr.processes_info() {
72-
session_mgr.destroy_session(&process.id);
73-
}
74-
// Double check again.
75-
for process in session_mgr.processes_info() {
76-
debug!("process {process:?} still running after drop, something must be wrong");
77-
}
78-
}
79-
8065
GlobalInstance::drop_testing(&self.thread_name);
8166
}
8267
}

0 commit comments

Comments
 (0)