Skip to content

Commit 6093bbb

Browse files
committed
Tests: Stop DB connection pool.
1 parent 808e777 commit 6093bbb

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

test/UserControllerTest.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,8 @@ void UserControllerTest::onRun() {
7676
/* wait all server threads finished */
7777
std::this_thread::sleep_for(std::chrono::seconds(1));
7878

79+
/* stop db connection pool */
80+
OATPP_COMPONENT(std::shared_ptr<oatpp::provider::Provider<oatpp::sqlite::Connection>>, dbConnectionProvider);
81+
dbConnectionProvider->stop();
82+
7983
}

test/app/TestDatabaseComponent.hpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,30 @@ class TestDatabaseComponent {
88
public:
99

1010
/**
11-
* Create database client
11+
* Create database connection provider component
1212
*/
13-
OATPP_CREATE_COMPONENT(std::shared_ptr<UserDb>, userDb)([] {
13+
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::provider::Provider<oatpp::sqlite::Connection>>, dbConnectionProvider)([] {
1414

1515
/* Create database-specific ConnectionProvider */
1616
auto connectionProvider = std::make_shared<oatpp::sqlite::ConnectionProvider>(TESTDATABASE_FILE);
1717

1818
/* Create database-specific ConnectionPool */
19-
auto connectionPool = oatpp::sqlite::ConnectionPool::createShared(connectionProvider,
20-
10 /* max-connections */,
21-
std::chrono::seconds(5) /* connection TTL */);
19+
return oatpp::sqlite::ConnectionPool::createShared(connectionProvider,
20+
10 /* max-connections */,
21+
std::chrono::seconds(5) /* connection TTL */);
22+
23+
}());
24+
25+
/**
26+
* Create database client
27+
*/
28+
OATPP_CREATE_COMPONENT(std::shared_ptr<UserDb>, userDb)([] {
29+
30+
/* Get database ConnectionProvider component */
31+
OATPP_COMPONENT(std::shared_ptr<oatpp::provider::Provider<oatpp::sqlite::Connection>>, connectionProvider);
2232

2333
/* Create database-specific Executor */
24-
auto executor = std::make_shared<oatpp::sqlite::Executor>(connectionPool);
34+
auto executor = std::make_shared<oatpp::sqlite::Executor>(connectionProvider);
2535

2636
/* Create MyClient database client */
2737
return std::make_shared<UserDb>(executor);

0 commit comments

Comments
 (0)