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
1 change: 1 addition & 0 deletions src/client/Session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ ExecutionResponse Session::executeWithParameter(
const std::string &stmt, const std::unordered_map<std::string, Value> &parameters) {
if (connectionIsBroken_ && retryConnect_) {
if (retryConnect() == nebula::ErrorCode::SUCCEEDED) {
connectionIsBroken_ = false;
return ExecutionResponse(conn_.executeWithParameter(sessionId_, stmt, parameters));
} else {
return ExecutionResponse{ErrorCode::E_RPC_FAILURE,
Expand Down
31 changes: 29 additions & 2 deletions src/client/tests/SessionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,26 @@
*/

#include <common/Init.h>
#include <common/datatypes/DataSet.h>
#include <common/datatypes/Geography.h>
#include <folly/json.h>
#include <folly/synchronization/Baton.h>
#include <glog/logging.h>
#include <gtest/gtest.h>
#include <gtest/gtest_prod.h>
#include <nebula/client/Config.h>
#include <nebula/client/ConnectionPool.h>
#include <nebula/client/Session.h>
#include <nebula/client/Connection.h>

#include <atomic>
#include <chrono>
#include <thread>

#define private public
#include <nebula/client/Session.h>
#undef private

#include <nebula/client/ConnectionPool.h>

#include "./ClientTest.h"
#include "common/graph/Response.h"

Expand Down Expand Up @@ -101,6 +107,27 @@ TEST_F(SessionTest, Basic) {
runOnce(pool);
}

TEST_F(SessionTest, PreflightReconnectClearsBrokenFlag) {
nebula::Config config;
config.maxConnectionPoolSize_ = 1;

nebula::ConnectionPool pool;
pool.init({kServerHost ":9669"}, config);
auto session = pool.getSession("root", "nebula");
ASSERT_TRUE(session.valid());

session.connectionIsBroken_.store(true);
auto resp = session.execute("YIELD 1");
ASSERT_EQ(resp.errorCode, nebula::ErrorCode::SUCCEEDED);
EXPECT_FALSE(session.connectionIsBroken_.load());

const auto stableSessionId = session.sessionId_;
resp = session.execute("YIELD 1");
ASSERT_EQ(resp.errorCode, nebula::ErrorCode::SUCCEEDED);
EXPECT_EQ(session.sessionId_, stableSessionId);
EXPECT_FALSE(session.connectionIsBroken_.load());
}

TEST_F(SessionTest, OverUse) {
nebula::ConnectionPool pool;
nebula::Config c;
Expand Down