From f8651c2c5597b5953e5d61d14005016d92ad591e Mon Sep 17 00:00:00 2001 From: chenshi5012 <10794822+chenshi5012@users.noreply.github.com> Date: Wed, 14 Oct 2026 09:48:49 +0000 Subject: [PATCH] Fix SessionPool move constructor --- include/nebula/client/SessionPool.h | 4 +++- src/client/tests/SessionPoolTest.cpp | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/include/nebula/client/SessionPool.h b/include/nebula/client/SessionPool.h index 09b3c66a..106a4d70 100644 --- a/include/nebula/client/SessionPool.h +++ b/include/nebula/client/SessionPool.h @@ -39,7 +39,9 @@ class SessionPool { : config_(std::move(config)), pool_(new ConnectionPool()) {} SessionPool(const SessionPool &) = delete; // no copy SessionPool(SessionPool &&pool) - : config_(std::move(pool.config_)), pool_(std::move(pool.pool_)) {} + : config_(std::move(pool.config_)), + pool_(std::move(pool.pool_)), + idleSessions_(std::move(pool.idleSessions_)) {} // initialize session and context // return false when failed, otherwise return true diff --git a/src/client/tests/SessionPoolTest.cpp b/src/client/tests/SessionPoolTest.cpp index fe2105ce..28fef109 100644 --- a/src/client/tests/SessionPoolTest.cpp +++ b/src/client/tests/SessionPoolTest.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include "./ClientTest.h" @@ -83,6 +84,26 @@ TEST_F(SessionPoolTest, Basic) { } } +TEST_F(SessionPoolTest, MoveConstructorTransfersIdleSessions) { + nebula::SessionPoolConfig config; + config.username_ = "root"; + config.password_ = "nebula"; + config.addrs_ = {kServerHost ":9669"}; + config.spaceName_ = "session_pool_test"; + config.maxSize_ = 1; + + nebula::SessionPool source(config); + ASSERT_TRUE(source.init()); + { + // Destroy the moved-to pool first. The moved-from object must no longer + // retain sessions that refer to the transferred ConnectionPool. + nebula::SessionPool moved(std::move(source)); + auto resp = moved.execute("YIELD 1"); + ASSERT_EQ(resp.errorCode, nebula::ErrorCode::SUCCEEDED) + << (resp.errorMsg ? *resp.errorMsg : ""); + } +} + // case 1 TEST_F(SessionPoolTest, Exception) { // space don't exists