Skip to content

Commit 3bacbc4

Browse files
committed
Bug #30532629: FIX SPORADIC FAILURES OF SESS.POOL_TTL TEST
1 parent 5f5968a commit 3bacbc4

File tree

3 files changed

+64
-45
lines changed

3 files changed

+64
-45
lines changed

common/session.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ void Settings_impl::get_data_source(cdk::ds::Multi_source &src)
403403

404404
if (has_option(Session_option_impl::DNS_SRV))
405405
{
406-
/*
406+
/*
407407
Use DNS+SRV data source.
408408
409409
Note: option consistency checks are done by Setter
@@ -744,9 +744,7 @@ void Session_pool::close()
744744
el.second.m_cleanup->cleanup();
745745
el.first->close();
746746
} catch(...)
747-
{
748-
assert(false);
749-
}
747+
{}
750748
}
751749
m_pool.clear();
752750

devapi/tests/session-t.cc

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2165,6 +2165,8 @@ TEST_F(Sess, pool_ttl)
21652165
std::chrono::seconds queue_timeout(50);
21662166
std::chrono::milliseconds pool_ttl(500);
21672167

2168+
get_sess().createSchema("pool_ttl", true);
2169+
21682170
ClientSettings settings(ClientOption::POOLING, true,
21692171
SessionOption::AUTH, AuthMethod::SHA256_MEMORY,
21702172
SessionOption::SSL_MODE, SSLMode::DISABLED,
@@ -2179,9 +2181,7 @@ TEST_F(Sess, pool_ttl)
21792181
SessionOption::PRIORITY, 1,
21802182
SessionOption::USER, get_user(),
21812183
SessionOption::PWD, get_password(),
2182-
SessionOption::DB, "test");
2183-
2184-
#if 1
2184+
SessionOption::DB, "pool_ttl");
21852185

21862186
// threaded example
21872187
{
@@ -2277,11 +2277,6 @@ TEST_F(Sess, pool_ttl)
22772277

22782278
}
22792279

2280-
#endif
2281-
2282-
// Temporary disabled, bug#30532629
2283-
2284-
#if 0
22852280
{
22862281
std::cout << "Not threaded" << std::endl;
22872282

@@ -2291,13 +2286,13 @@ TEST_F(Sess, pool_ttl)
22912286
mysqlx::Client client(settings);
22922287

22932288

2294-
auto get_sessions = [&client, &max_connections]()
2289+
auto get_sessions = [&client, max_connections]()
22952290
{
22962291
std::list<mysqlx::Session> sessions;
22972292
for (int i = 0; i < max_connections; ++i)
22982293
{
22992294
sessions.emplace_back(client);
2300-
EXPECT_EQ(1, sessions.back().sql("select 1").execute()
2295+
EXPECT_EQ(1, sessions.back().sql("select 1").execute().count());
23012296
}
23022297
};
23032298

@@ -2307,17 +2302,29 @@ TEST_F(Sess, pool_ttl)
23072302

23082303
std::vector<int> proccess_ids;
23092304

2310-
int this_thread_id = sql("SELECT CONNECTION_ID()").fetchOne()[0].get<int>();
2305+
auto proccesslist = sql("show processlist");
23112306

2312-
std::list<Row> rows = sql("show processlist").fetchAll();
2307+
unsigned db_idx = 0;
23132308

2314-
for (auto row : rows)
2309+
for(auto column : proccesslist.getColumns())
23152310
{
2316-
auto val = row.get(7);
2317-
int thread_id = row.get(0).get<int>();
2318-
if (val.isNull() ||
2319-
continue;
2311+
if (column.getColumnLabel() == "db" )
2312+
{
2313+
break;
2314+
}
2315+
++db_idx;
2316+
}
2317+
2318+
EXPECT_LT(db_idx,proccesslist.getColumnCount());
23202319

2320+
for (auto row : proccesslist)
2321+
{
2322+
//UT created sessions all use pool_ttl schema, so we will look for
2323+
//connections having that schema to kill them
2324+
auto db = row.get(db_idx);
2325+
if (db.isNull() || db.get<string>() != "pool_ttl")
2326+
continue;
2327+
int thread_id = row.get(0).get<int>();
23212328
proccess_ids.push_back(thread_id);
23222329
}
23232330

@@ -2334,19 +2341,23 @@ TEST_F(Sess, pool_ttl)
23342341

23352342
sql("set global mysqlx_wait_timeout=20");
23362343

2344+
std::cout << "Get sessions" << std::endl;
2345+
23372346
get_sessions();
23382347

2339-
std::this_thread::sleep_for(std::chrono::seconds(20));
2348+
std::cout << "Wait 25s to timeout sessions" << std::endl;
2349+
std::this_thread::sleep_for(std::chrono::seconds(25));
2350+
2351+
std::cout << "Get sessions" << std::endl;
23402352

23412353
get_sessions();
23422354

2355+
//Create a new session, since previous has timed-out!
2356+
create_session();
23432357
std::cout << "set global mysqlx_wait_timeout=28800" << std::endl;
2344-
client.getSession().sql("set global mysqlx_wait_timeout=28800").execute();
2358+
sql("set global mysqlx_wait_timeout=28800");
23452359
}
23462360

2347-
#endif // 0
2348-
2349-
23502361
{
23512362
settings.set(ClientOption::POOL_MAX_SIZE, 1);
23522363

testing/test.h

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -116,25 +116,7 @@ class Xplugin : public ::testing::Test
116116

117117
m_password = getenv("XPLUGIN_PASSWORD");
118118

119-
try {
120-
m_client = new mysqlx::Client(
121-
SessionOption::HOST, m_host,
122-
SessionOption::PORT, m_port,
123-
SessionOption::USER, m_user,
124-
SessionOption::PWD, m_password
125-
);
126-
m_sess = new mysqlx::Session(*m_client);
127-
}
128-
catch (const Error &e)
129-
{
130-
delete m_client;
131-
delete m_sess;
132-
m_client = NULL;
133-
m_sess = NULL;
134-
m_status = e.what();
135-
FAIL() << "Could not connect to xplugin at " << m_port
136-
<< " (" << m_host << ")" << ": " << e;
137-
}
119+
create_session();
138120

139121
// Drop and re-create test schema to clear up after previous tests.
140122

@@ -179,6 +161,34 @@ class Xplugin : public ::testing::Test
179161
return *m_sess;
180162
}
181163

164+
void create_session()
165+
{
166+
try {
167+
if(!m_client)
168+
{
169+
m_client = new mysqlx::Client(
170+
SessionOption::HOST, m_host,
171+
SessionOption::PORT, m_port,
172+
SessionOption::USER, m_user,
173+
SessionOption::PWD, m_password
174+
);
175+
}
176+
delete m_sess;
177+
m_sess = nullptr;
178+
m_sess = new mysqlx::Session(*m_client);
179+
}
180+
catch (const Error &e)
181+
{
182+
delete m_client;
183+
delete m_sess;
184+
m_client = NULL;
185+
m_sess = NULL;
186+
m_status = e.what();
187+
FAIL() << "Could not connect to xplugin at " << m_port
188+
<< " (" << m_host << ")" << ": " << e;
189+
}
190+
}
191+
182192
const char* get_host() const
183193
{
184194
return m_host;

0 commit comments

Comments
 (0)