Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion include/nebula/client/SessionPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions src/client/tests/SessionPoolTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <atomic>
#include <chrono>
#include <thread>
#include <utility>

#include "./ClientTest.h"

Expand Down Expand Up @@ -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
Expand Down