diff --git a/include/nebula/client/SessionPool.h b/include/nebula/client/SessionPool.h index 09b3c66..106a4d7 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 fe2105c..28fef10 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