Commit 2a88b465 authored by Georgios Bitzes's avatar Georgios Bitzes
Browse files

Implement ClusterDestabilizer test utility which repeatedly rotates leader

parent 7280becb
Pipeline #1458794 failed with stages
in 69 minutes
......@@ -139,6 +139,10 @@ RaftClusterID TestCluster::clusterID() {
return clusterid;
}
size_t TestCluster::getClusterSize() const {
return testnodes.size();
}
ShardDirectory* TestCluster::shardDirectory(int id) {
return node(id)->shardDirectory();
}
......@@ -407,5 +411,27 @@ bool IptablesHelper::singleAcceptPackets(int port) {
return system(SSTR("iptables -I OUTPUT -p tcp --dest 127.0.0.1 --dport " << port << " -j ACCEPT").c_str()) == 0;
}
ClusterDestabilizer::ClusterDestabilizer(TestCluster *testCluster)
: mTestCluster(testCluster) {
mThread.reset(&ClusterDestabilizer::main, this);
}
ClusterDestabilizer::~ClusterDestabilizer() {}
void ClusterDestabilizer::main(ThreadAssistant &assistant) {
assistant.wait_for(mTestCluster->timeouts().getLow());
while(!assistant.terminationRequested()) {
int leaderID = mTestCluster->getLeaderID();
if(leaderID >= 0) {
mTestCluster->spindown(leaderID);
assistant.wait_for(mTestCluster->timeouts().getLow());
mTestCluster->spinup(leaderID);
}
assistant.wait_for(mTestCluster->timeouts().getHigh() * 2);
}
}
}
......@@ -243,6 +243,7 @@ public:
std::vector<RaftServer> nodes(int id = 0);
qclient::Members members(int id = 0);
RaftClusterID clusterID();
size_t getClusterSize() const;
template<typename... Args>
bool checkValueConsensus(const std::string &key, const std::string &value, const Args... args) {
......@@ -402,6 +403,19 @@ private:
std::map<int, TestNode*> testnodes;
};
// Given a test cluster, shut down the leader on regular intervals.
class ClusterDestabilizer {
public:
ClusterDestabilizer(TestCluster *testCluster);
~ClusterDestabilizer();
void main(ThreadAssistant &assistant);
private:
TestCluster *mTestCluster;
AssistedThread mThread;
};
// Convenience classes. Want to run tests on a simulated cluster of 3 nodes?
// Inherit your test fixture from here.
class TestCluster3Nodes : public TestCluster {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment