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
12 changes: 11 additions & 1 deletion modules/platforms/cpp/thin-client-test/include/test_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,16 @@ class TestServer
responses.push_back(resp);
}

/**
* Get port that server is listening on.
*
* @return TCP port.
*/
uint16_t GetPort() const
{
return acceptor.local_endpoint().port();
}

/**
* Get specified session.
* @param idx Index.
Expand Down Expand Up @@ -210,4 +220,4 @@ class TestServer

} // namespace ignite

#endif //_IGNITE_THIN_CLIENT_TEST_TEST_SERVER
#endif //_IGNITE_THIN_CLIENT_TEST_TEST_SERVER
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include <boost/test/unit_test.hpp>
#include <boost/bind.hpp>

#include <sstream>

#include <ignite/ignition.h>

#include <ignite/thin/ignite_client_configuration.h>
Expand Down Expand Up @@ -81,7 +83,7 @@ class IgniteClientTestSuiteFixture
*/
static void CheckThreadsNum(IgniteClientConfiguration &cfg, uint32_t num)
{
ignite::TestServer server;
ignite::TestServer server(0);
server.PushHandshakeResponse(true);
server.Start();

Expand All @@ -95,22 +97,47 @@ class IgniteClientTestSuiteFixture
int32_t threadsExpected = static_cast<int32_t>(num) + netThreads;

cfg.SetUserThreadPoolSize(num);

std::stringstream endpoint;
endpoint << "127.0.0.1:" << server.GetPort();
cfg.SetEndPoints(endpoint.str());

{
IgniteClient client = IgniteClient::Start(cfg);

int32_t threadsActual = ignite::common::concurrent::GetThreadsCount() - threadsBefore;

BOOST_CHECK_EQUAL(threadsExpected, threadsActual);
BOOST_CHECK(WaitForThreadsCount(threadsBefore + threadsExpected));
}

int32_t threadsAfter = ignite::common::concurrent::GetThreadsCount();

BOOST_CHECK_EQUAL(threadsBefore, threadsAfter);
BOOST_CHECK(WaitForThreadsCount(threadsBefore));
BOOST_CHECK_EQUAL(num, cfg.GetUserThreadPoolSize());

server.Stop();
}

/**
* Wait for threads count.
*
* @param expected Expected threads count.
* @return True if condition was met, false if timeout has been reached.
*/
static bool WaitForThreadsCount(int32_t expected)
{
return ignite_test::WaitForCondition(
boost::bind(&IgniteClientTestSuiteFixture::CheckThreadsCount, expected),
5000);
}

/**
* Check threads count.
*
* @param expected Expected threads count.
* @return @c true on success.
*/
static bool CheckThreadsCount(int32_t expected)
{
return ignite::common::concurrent::GetThreadsCount() == expected;
}

/**
* Check number of active connections.
*
Expand Down