Skip to content

Commit

Permalink
return a json instead of a hardcoded string
Browse files Browse the repository at this point in the history
  • Loading branch information
csegarragonz committed Dec 13, 2021
1 parent 2cf0ae8 commit 05523e4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 30 deletions.
7 changes: 2 additions & 5 deletions src/endpoint/FaabricEndpointHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,8 @@ std::pair<int, std::string> FaabricEndpointHandler::handleFunction(
if (result.type() == faabric::Message_MessageType_EMPTY) {
response = std::make_pair(0, "RUNNING");
} else if (result.returnvalue() == 0) {
std::string responseStr =
fmt::format("SUCCESS: {}\nExecuted time (ms): {}",
result.outputdata(),
result.finishtimestamp() - result.timestamp());
response = std::make_pair(0, responseStr);
response =
std::make_pair(0, faabric::util::messageToJson(result));
} else {
response = std::make_pair(1, "FAILED: " + result.outputdata());
}
Expand Down
26 changes: 6 additions & 20 deletions tests/test/endpoint/test_endpoint_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
#include <faabric/util/json.h>
#include <faabric/util/macros.h>

#define ASYNC_REQ_SLEEP_MS 3000

using namespace Pistache;
using namespace faabric::scheduler;

Expand Down Expand Up @@ -47,9 +45,7 @@ class EndpointApiTestExecutor final : public Executor
"Endpoint API returning {} for {}", returnVal, msg.id()));
} else if (msg.isasync()) {
returnVal = 0;
SLEEP_MS(ASYNC_REQ_SLEEP_MS);
msg.set_finishtimestamp(
faabric::util::getGlobalClock().epochMillis());
SLEEP_MS(3000);
msg.set_outputdata(
fmt::format("Finished async message {}", msg.id()));
} else {
Expand Down Expand Up @@ -191,21 +187,11 @@ TEST_CASE_METHOD(EndpointApiTestFixture,
submitGetRequestToUrl(LOCALHOST, port, statusBody);

REQUIRE(statusResultAfter.first == 200);
std::stringstream ss(statusResultAfter.second);
// Check the part with the output text first
std::string outputDataStr;
std::getline(ss, outputDataStr, '\n');
REQUIRE(outputDataStr ==
fmt::format("SUCCESS: Finished async message {}", msg.id()));
// Then check the executed time string
std::string executedTimeStr;
std::getline(ss, executedTimeStr, ':');
REQUIRE(executedTimeStr == fmt::format("Executed time (ms)"));
// Lastly, sanity check that the executed time returned is greater than the
// sleep in the executor
std::string executedTime;
std::getline(ss, executedTime);
REQUIRE(std::stoi(executedTime) > ASYNC_REQ_SLEEP_MS);
faabric::Message resultMsg =
faabric::util::jsonToMessage(statusResultAfter.second);
REQUIRE(resultMsg.returnvalue() == 0);
REQUIRE(resultMsg.outputdata() ==
fmt::format("Finished async message {}", msg.id()));

endpoint.stop();

Expand Down
6 changes: 1 addition & 5 deletions tests/test/endpoint/test_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,9 @@ TEST_CASE_METHOD(EndpointHandlerTestFixture,
std::string errorMsg = "I have succeeded";
msg.set_outputdata(errorMsg);
msg.set_returnvalue(0);
// Enforce an exactly 0 execution time
auto ts = faabric::util::getGlobalClock().epochMillis();
msg.set_timestamp(ts);
msg.set_finishtimestamp(ts);
sch.setFunctionResult(msg);

expectedOutput = "SUCCESS: " + errorMsg + "\nExecuted time (ms): 0";
expectedOutput = faabric::util::messageToJson(msg);
}

msg.set_isstatusrequest(true);
Expand Down

0 comments on commit 05523e4

Please sign in to comment.