mirror of
https://gitee.com/an-tao/drogon.git
synced 2024-12-02 11:47:56 +08:00
Add transactions test of coroutines (#711)
This commit is contained in:
parent
33044c823f
commit
cfb71cc619
@ -300,12 +300,12 @@ inline void internal::TrasactionAwaiter::await_suspend(
|
||||
{
|
||||
assert(client_ != nullptr);
|
||||
client_->newTransactionAsync(
|
||||
[this, handle](const std::shared_ptr<Transaction> transacton) {
|
||||
if (transacton == nullptr)
|
||||
[this, handle](const std::shared_ptr<Transaction> &transaction) {
|
||||
if (transaction == nullptr)
|
||||
setException(std::make_exception_ptr(
|
||||
std::runtime_error("Failed to create transaction")));
|
||||
Failure("Failed to create transaction")));
|
||||
else
|
||||
setValue(transacton);
|
||||
setValue(transaction);
|
||||
handle.resume();
|
||||
});
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ using namespace drogon::orm;
|
||||
#define GREEN "\033[32m" /* Green */
|
||||
|
||||
#ifdef __cpp_impl_coroutine
|
||||
constexpr int postgre_tests = 46;
|
||||
constexpr int postgre_tests = 47;
|
||||
constexpr int mysql_tests = 47;
|
||||
constexpr int sqlite_tests = 49;
|
||||
#else
|
||||
@ -743,9 +743,9 @@ void doPostgreTest(const drogon::orm::DbClientPtr &clientPtr)
|
||||
testOutput(result.size() != 0,
|
||||
"postgresql - DbClient coroutine interface(0)");
|
||||
}
|
||||
catch (const Failure &e)
|
||||
catch (const DrogonDbException &e)
|
||||
{
|
||||
std::cerr << e.what() << std::endl;
|
||||
std::cerr << e.base().what() << std::endl;
|
||||
testOutput(false, "postgresql - DbClient coroutine interface(0)");
|
||||
}
|
||||
/// 7.2 Parameter binding
|
||||
@ -756,11 +756,26 @@ void doPostgreTest(const drogon::orm::DbClientPtr &clientPtr)
|
||||
testOutput(result.size() != 0,
|
||||
"postgresql - DbClient coroutine interface(1)");
|
||||
}
|
||||
catch (const Failure &e)
|
||||
catch (const DrogonDbException &e)
|
||||
{
|
||||
std::cerr << e.what() << std::endl;
|
||||
std::cerr << e.base().what() << std::endl;
|
||||
testOutput(false, "postgresql - DbClient coroutine interface(1)");
|
||||
}
|
||||
/// 7.3 Transactions
|
||||
try
|
||||
{
|
||||
auto trans = co_await clientPtr->newTransactionCoro();
|
||||
auto result =
|
||||
co_await trans->execSqlCoro("select * from users where 1=$1;",
|
||||
1);
|
||||
testOutput(result.size() != 0,
|
||||
"postgresql - DbClient coroutine interface(2)");
|
||||
}
|
||||
catch (const DrogonDbException &e)
|
||||
{
|
||||
std::cerr << e.base().what() << std::endl;
|
||||
testOutput(false, "postgresql - DbClient coroutine interface(2)");
|
||||
}
|
||||
};
|
||||
drogon::sync_wait(coro_test());
|
||||
#endif
|
||||
@ -1394,12 +1409,12 @@ void doMysqlTest(const drogon::orm::DbClientPtr &clientPtr)
|
||||
auto result =
|
||||
co_await clientPtr->execSqlCoro("select * from users;");
|
||||
testOutput(result.size() != 0,
|
||||
"postgresql - DbClient coroutine interface(0)");
|
||||
"mysql - DbClient coroutine interface(0)");
|
||||
}
|
||||
catch (const Failure &e)
|
||||
catch (const DrogonDbException &e)
|
||||
{
|
||||
std::cerr << e.what() << std::endl;
|
||||
testOutput(false, "postgresql - DbClient coroutine interface(0)");
|
||||
std::cerr << e.base().what() << std::endl;
|
||||
testOutput(false, "mysql - DbClient coroutine interface(0)");
|
||||
}
|
||||
/// 7.2 Parameter binding
|
||||
try
|
||||
@ -1407,12 +1422,12 @@ void doMysqlTest(const drogon::orm::DbClientPtr &clientPtr)
|
||||
auto result = co_await clientPtr->execSqlCoro(
|
||||
"select * from users where 1=?;", 1);
|
||||
testOutput(result.size() != 0,
|
||||
"postgresql - DbClient coroutine interface(1)");
|
||||
"mysql - DbClient coroutine interface(1)");
|
||||
}
|
||||
catch (const Failure &e)
|
||||
catch (const DrogonDbException &e)
|
||||
{
|
||||
std::cerr << e.what() << std::endl;
|
||||
testOutput(false, "postgresql - DbClient coroutine interface(1)");
|
||||
std::cerr << e.base().what() << std::endl;
|
||||
testOutput(false, "mysql - DbClient coroutine interface(1)");
|
||||
}
|
||||
};
|
||||
drogon::sync_wait(coro_test());
|
||||
@ -2074,12 +2089,12 @@ void doSqliteTest(const drogon::orm::DbClientPtr &clientPtr)
|
||||
auto result =
|
||||
co_await clientPtr->execSqlCoro("select * from users;");
|
||||
testOutput(result.size() != 0,
|
||||
"postgresql - DbClient coroutine interface(0)");
|
||||
"sqlite3 - DbClient coroutine interface(0)");
|
||||
}
|
||||
catch (const Failure &e)
|
||||
catch (const DrogonDbException &e)
|
||||
{
|
||||
std::cerr << e.what() << std::endl;
|
||||
testOutput(false, "postgresql - DbClient coroutine interface(0)");
|
||||
std::cerr << e.base().what() << std::endl;
|
||||
testOutput(false, "sqlite3 - DbClient coroutine interface(0)");
|
||||
}
|
||||
/// 7.2 Parameter binding
|
||||
try
|
||||
@ -2087,12 +2102,12 @@ void doSqliteTest(const drogon::orm::DbClientPtr &clientPtr)
|
||||
auto result = co_await clientPtr->execSqlCoro(
|
||||
"select * from users where 1=?;", 1);
|
||||
testOutput(result.size() != 0,
|
||||
"postgresql - DbClient coroutine interface(1)");
|
||||
"sqlite3 - DbClient coroutine interface(1)");
|
||||
}
|
||||
catch (const Failure &e)
|
||||
catch (const DrogonDbException &e)
|
||||
{
|
||||
std::cerr << e.what() << std::endl;
|
||||
testOutput(false, "postgresql - DbClient coroutine interface(1)");
|
||||
std::cerr << e.base().what() << std::endl;
|
||||
testOutput(false, "sqlite3 - DbClient coroutine interface(1)");
|
||||
}
|
||||
};
|
||||
drogon::sync_wait(coro_test());
|
||||
|
2
trantor
2
trantor
@ -1 +1 @@
|
||||
Subproject commit b7c16286cdd4147e6ddf6b3831dc0578c794c10b
|
||||
Subproject commit e35fd046ac8a58bec3557c0c207a3e0b8ae57d38
|
Loading…
Reference in New Issue
Block a user