Skip to content

Commit

Permalink
Merge pull request #1981 from Expensify/main
Browse files Browse the repository at this point in the history
Update expensify_prod branch
  • Loading branch information
pecanoro authored Nov 26, 2024
2 parents a329e6e + d8e7b91 commit 3e1eb62
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
11 changes: 9 additions & 2 deletions BedrockServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1821,14 +1821,21 @@ thread* __quiesceThread = nullptr;

void BedrockServer::_control(unique_ptr<BedrockCommand>& command) {
SData& response = command->response;
string reason = "MANUAL";
response.methodLine = "200 OK";
if (SIEquals(command->request.methodLine, "BeginBackup")) {
_shouldBackup = true;
_beginShutdown("Detach", true);
} else if (SIEquals(command->request.methodLine, "SuppressCommandPort")) {
blockCommandPort("MANUAL");
if (command->request.isSet("reason") && command->request["reason"].size()) {
reason = command->request["reason"];
}
blockCommandPort(reason);
} else if (SIEquals(command->request.methodLine, "ClearCommandPort")) {
unblockCommandPort("MANUAL");
if (command->request.isSet("reason") && command->request["reason"].size()) {
reason = command->request["reason"];
}
unblockCommandPort(reason);
} else if (SIEquals(command->request.methodLine, "ClearCrashCommands")) {
unique_lock<decltype(_crashCommandMutex)> lock(_crashCommandMutex);
_crashCommands.clear();
Expand Down
39 changes: 39 additions & 0 deletions test/tests/CommandPortTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include <libstuff/SData.h>
#include <test/lib/BedrockTester.h>

struct CommandPortTest : tpunit::TestFixture {
CommandPortTest()
: tpunit::TestFixture("CommandPort", TEST(CommandPortTest::test)) { }

void test() {
BedrockTester tester;

// When we close the command port with a reason
SData closeCommandPort("SuppressCommandPort");
closeCommandPort["reason"] = "testCommandPort";
STable response = SParseJSONObject(tester.executeWaitMultipleData({closeCommandPort})[0].content);

// The status command should show it in commandPortBlockReasons
SData status("Status");
response = SParseJSONObject(tester.executeWaitMultipleData({status}, 10, true)[0].content);
ASSERT_EQUAL(SParseJSONArray(response["commandPortBlockReasons"]), list<string>{"testCommandPort"});

// When we run ClearCommandPort with a reason different from the one used to close it
SData badClearCommandPort("ClearCommandPort");
tester.executeWaitMultipleData({badClearCommandPort}, 10, true);

// The command port should stay close and the status command should still show the reason the port is closed in commandPortBlockReasons
response = SParseJSONObject(tester.executeWaitMultipleData({status}, 10, true)[0].content);
ASSERT_EQUAL(SParseJSONArray(response["commandPortBlockReasons"]), list<string>{"testCommandPort"});

// When we run ClearCommandPort with the same reason as the one used to close it
SData clearCommandPort("ClearCommandPort");
clearCommandPort["reason"] = "testCommandPort";
tester.executeWaitMultipleData({clearCommandPort}, 10, true);

// Then the command port should open and the reason should be removed from commandPortBlockReasons
response = SParseJSONObject(tester.executeWaitMultipleData({status})[0].content);
ASSERT_EQUAL(SParseJSONArray(response["commandPortBlockReasons"]), list<string>{});
}

} __CommandPortTest;

0 comments on commit 3e1eb62

Please sign in to comment.