summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-07-31 17:40:43 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2021-07-31 17:41:31 +0100
commitfeeb976e4ab4ffe1542dcd20d0ae5ea569bfc0bc (patch)
treeac9e30397bc149695f930855509730d15accfeca /test
parentBuild a basic hacky semaphore for compilers that don't support std::binary_se... (diff)
downloadmygrate-feeb976e4ab4ffe1542dcd20d0ae5ea569bfc0bc.tar.bz2
mygrate-feeb976e4ab4ffe1542dcd20d0ae5ea569bfc0bc.tar.xz
mygrate-feeb976e4ab4ffe1542dcd20d0ae5ea569bfc0bc.zip
Subclass UpdateDatabase to wait for N operations to be completed
Avoids need to sleep
Diffstat (limited to 'test')
-rw-r--r--test/test-e2e.cpp33
1 files changed, 29 insertions, 4 deletions
diff --git a/test/test-e2e.cpp b/test/test-e2e.cpp
index 0f5a051..f861603 100644
--- a/test/test-e2e.cpp
+++ b/test/test-e2e.cpp
@@ -2,6 +2,7 @@
#include <boost/test/data/test_case.hpp>
#include <boost/test/unit_test.hpp>
+#include "semaphore.h"
#include "testdb-mysql.h"
#include "testdb-postgresql.h"
#include <input/replStream.h>
@@ -11,7 +12,29 @@
#include <sql/selectTestTable.h>
#include <thread>
-BOOST_AUTO_TEST_CASE(e2e)
+class TestUpdateDatabase : public MyGrate::Output::Pq::UpdateDatabase {
+public:
+ using MyGrate::Output::Pq::UpdateDatabase::UpdateDatabase;
+ void
+ afterEvent(const MyGrate::MariaDB_Event_Ptr & e) override
+ {
+ UpdateDatabase::afterEvent(std::move(e));
+ ops.release();
+ }
+
+ void
+ waitFor(unsigned int n)
+ {
+ while (n--) {
+ ops.acquire();
+ }
+ }
+
+private:
+ semaphore ops {0};
+};
+
+BOOST_AUTO_TEST_CASE(e2e, *boost::unit_test::timeout(5))
{
const char * const target_schema {"testout"};
using namespace MyGrate::Testing;
@@ -24,8 +47,10 @@ BOOST_AUTO_TEST_CASE(e2e)
MyGrate::sql::createTestTable::execute(&mym);
MyGrate::sql::fillTestTable::execute(&mym);
- auto out = MyGrate::Output::Pq::UpdateDatabase::createNew(&pqm, MySQLDB::SERVER, MySQLDB::USER, MySQLDB::PASSWORD,
- MySQLDB::PORT, my.mockname.c_str(), 100, target_schema);
+ TestUpdateDatabase out {pqm.connstr.c_str(),
+ MyGrate::Output::Pq::UpdateDatabase::createNew(&pqm, MySQLDB::SERVER, MySQLDB::USER, MySQLDB::PASSWORD,
+ MySQLDB::PORT, my.mockname.c_str(), 100, target_schema)
+ .source};
BOOST_CHECK_EQUAL(out.source, 1);
auto src = out.getSource();
BOOST_REQUIRE(src);
@@ -46,7 +71,7 @@ BOOST_AUTO_TEST_CASE(e2e)
ins->execute({"hashyhash", "testuser", "groupadm", "10.10.0.1", 2433});
mym.query("flush logs");
- sleep(1);
+ out.waitFor(4);
src->stopEvents();
repl.join();