Skip to content

Commit

Permalink
Merge pull request #2048 from Expensify/main
Browse files Browse the repository at this point in the history
Update expensify_prod branch
  • Loading branch information
justinpersaud authored Jan 7, 2025
2 parents 6f437d5 + 30e9af3 commit 240ff5c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion test/clustertest/BedrockClusterTester.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ ClusterTester<T>::~ClusterTester()
// Shut down everything but the leader first.
list<thread> threads;

for (int i = 0; i< _size; i++) {
for (int i = 0; i < _size; i++) {
// Wait for all the commands to be done before stopping.
// If we don't do this, then if the leader loses quorum, because the other nodes have all shut down,
// it won't run remaining commands, and it will get stuck forever.
Expand Down
20 changes: 19 additions & 1 deletion test/lib/BedrockTester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ bool BedrockTester::readDB(const string& query, SQResult& result, bool online)
SData command("Query");
command["Query"] = fixedQuery;
command["Format"] = "JSON";
auto commandResult = executeWaitMultipleData({command});
auto commandResult = executeWaitMultipleData({command}, 1);
auto row0 = SParseJSONObject(commandResult[0].content)["rows"];
auto headerString = SParseJSONObject(commandResult[0].content)["headers"];

Expand Down Expand Up @@ -622,6 +622,24 @@ bool BedrockTester::waitForStatusTerm(const string& term, const string& testValu
return false;
}

bool BedrockTester::waitForLeadingFollowing(uint64_t timeoutUS) {
uint64_t start = STimeNow();
while (STimeNow() < start + timeoutUS) {
try {
string result = SParseJSONObject(BedrockTester::executeWaitVerifyContent(SData("Status"), "200", true))["state"];

// if the value matches, return, otherwise wait
if (result == "LEADING" || result == "FOLLOWING") {
return true;
}
} catch (...) {
// Doesn't do anything, we'll fall through to the sleep and try again.
}
usleep(100'000);
}
return false;
}

bool BedrockTester::waitForState(const string& state, uint64_t timeoutUS)
{
return waitForStatusTerm("state", state, timeoutUS);
Expand Down
5 changes: 4 additions & 1 deletion test/lib/BedrockTester.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class BedrockTester {
string startServer(bool wait = true);

// Stop a server by sending it a signal.
void stopServer(int signal = SIGTERM);
virtual void stopServer(int signal = SIGTERM);

// Shuts down all bedrock servers associated with any existing testers.
static void stopAll();
Expand Down Expand Up @@ -89,6 +89,9 @@ class BedrockTester {
// true if a match was found, or times out otherwose.
bool waitForStatusTerm(const string& term, const string& testValue, uint64_t timeoutUS = 60'000'000);

// Waits for the status to be either LEADING or FOLLOWING
bool waitForLeadingFollowing(uint64_t timeoutUS = 60'000'000);

// This is just a convenience wrapper around `waitForStatusTerm` looking for the state of the node.
bool waitForState(const string& state, uint64_t timeoutUS = 60'000'000);

Expand Down

0 comments on commit 240ff5c

Please sign in to comment.