summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-08-27 20:34:53 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2021-08-27 20:34:53 +0100
commite389d998b437e199592908e30779c5eb55490eb3 (patch)
treedb464af7b75ca4b4c89601215271cd58cd18b138
parentFix type mapping of real/double (diff)
downloadmygrate-e389d998b437e199592908e30779c5eb55490eb3.tar.bz2
mygrate-e389d998b437e199592908e30779c5eb55490eb3.tar.xz
mygrate-e389d998b437e199592908e30779c5eb55490eb3.zip
Handle errors in the replication thread in tests
-rw-r--r--test/test-e2e.cpp32
1 files changed, 30 insertions, 2 deletions
diff --git a/test/test-e2e.cpp b/test/test-e2e.cpp
index 45a8d49..d0d580c 100644
--- a/test/test-e2e.cpp
+++ b/test/test-e2e.cpp
@@ -53,6 +53,16 @@ class MockSetup {
public:
static constexpr const char * const target_schema {"testout"};
MockSetup() : pq {ROOT "/db/schema.sql"}, pqm {pq.mock()}, mym {my.mock()} { }
+ virtual ~MockSetup()
+ {
+ if (src) {
+ src->stopEvents();
+ }
+ if (repl) {
+ repl->join();
+ repl.reset();
+ }
+ }
TestUpdateDatabase &
getUpdateDatabase()
@@ -82,7 +92,19 @@ public:
{
BOOST_REQUIRE(out);
BOOST_REQUIRE(!repl);
- repl.emplace(&MyGrate::EventSourceBase::readEvents, getSource().get(), std::ref(*out));
+ repl.emplace([&]() {
+ try {
+ getSource()->readEvents(*out);
+ }
+ catch (std::exception & ex) {
+ failed = true;
+ std::cerr << ex.what() << "\n";
+ }
+ catch (...) {
+ failed = true;
+ std::cerr << "bug\n";
+ }
+ });
}
void
@@ -91,16 +113,22 @@ public:
BOOST_REQUIRE(out);
BOOST_REQUIRE(src);
BOOST_REQUIRE(repl);
- out->waitFor(events);
+ if (!failed) {
+ out->waitFor(events);
+ }
src->stopEvents();
repl->join();
repl.reset();
+ if (failed) {
+ throw std::runtime_error("Replication thread failed");
+ }
}
MySQLDB my;
PqConnDB pq;
MyGrate::Output::Pq::PqConn pqm;
MyGrate::Input::MySQLConn mym;
+ bool failed {false};
std::optional<TestUpdateDatabase> out;
MyGrate::EventSourceBasePtr src;