diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-12-07 14:15:26 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-12-07 14:15:26 +0000 |
commit | 6d8b2a4e9efa19e93d5cc3732ab7d00baf7566f1 (patch) | |
tree | 2bf6a1310271eddcd5127c34739c4ea6465b2150 /libpqpp/unittests/testpq.cpp | |
parent | Fix leak of error message in exception (diff) | |
download | libdbpp-postgresql-6d8b2a4e9efa19e93d5cc3732ab7d00baf7566f1.tar.bz2 libdbpp-postgresql-6d8b2a4e9efa19e93d5cc3732ab7d00baf7566f1.tar.xz libdbpp-postgresql-6d8b2a4e9efa19e93d5cc3732ab7d00baf7566f1.zip |
Improve connection failure detection
Diffstat (limited to 'libpqpp/unittests/testpq.cpp')
-rw-r--r-- | libpqpp/unittests/testpq.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/libpqpp/unittests/testpq.cpp b/libpqpp/unittests/testpq.cpp index 002b18c..3f55c63 100644 --- a/libpqpp/unittests/testpq.cpp +++ b/libpqpp/unittests/testpq.cpp @@ -169,6 +169,44 @@ BOOST_AUTO_TEST_CASE( insertId ) delete ro; } +BOOST_AUTO_TEST_CASE( reconnect ) +{ + auto ro = DB::MockDatabase::openConnectionTo("pqmock"); + auto rok = DB::MockDatabase::openConnectionTo("pqmock"); + auto pqconn = dynamic_cast<PQ::Connection *>(ro); + int pid1 = PQbackendPID(pqconn->conn); + BOOST_REQUIRE(pid1); + ro->ping(); + auto kil = rok->newModifyCommand("SELECT pg_terminate_backend(?)"); + kil->bindParamI(0, pid1); + kil->execute(); + delete kil; + ro->ping(); + int pid2 = PQbackendPID(pqconn->conn); + BOOST_REQUIRE(pid2); + BOOST_REQUIRE(pid1 != pid2); + delete ro; + delete rok; +} + +BOOST_AUTO_TEST_CASE( reconnectInTx ) +{ + auto ro = DB::MockDatabase::openConnectionTo("pqmock"); + auto rok = DB::MockDatabase::openConnectionTo("pqmock"); + auto pqconn = dynamic_cast<PQ::Connection *>(ro); + int pid1 = PQbackendPID(pqconn->conn); + BOOST_REQUIRE(pid1); + ro->ping(); + ro->beginTx(); + auto kil = rok->newModifyCommand("SELECT pg_terminate_backend(?)"); + kil->bindParamI(0, pid1); + kil->execute(); + delete kil; + BOOST_REQUIRE_THROW(ro->ping(), PQ::ConnectionError); + delete ro; + delete rok; +} + BOOST_AUTO_TEST_SUITE_END(); BOOST_AUTO_TEST_CASE( connfail ) |