From 05523e4e579412eab7ce65845f66e77a4d908dbe Mon Sep 17 00:00:00 2001 From: Carlos Segarra Date: Mon, 13 Dec 2021 14:34:12 +0000 Subject: [PATCH] return a json instead of a hardcoded string --- src/endpoint/FaabricEndpointHandler.cpp | 7 ++---- tests/test/endpoint/test_endpoint_api.cpp | 26 ++++++----------------- tests/test/endpoint/test_handler.cpp | 6 +----- 3 files changed, 9 insertions(+), 30 deletions(-) diff --git a/src/endpoint/FaabricEndpointHandler.cpp b/src/endpoint/FaabricEndpointHandler.cpp index 43ad7280f..c711c2d49 100644 --- a/src/endpoint/FaabricEndpointHandler.cpp +++ b/src/endpoint/FaabricEndpointHandler.cpp @@ -70,11 +70,8 @@ std::pair 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()); } diff --git a/tests/test/endpoint/test_endpoint_api.cpp b/tests/test/endpoint/test_endpoint_api.cpp index 933093a41..1764636f8 100644 --- a/tests/test/endpoint/test_endpoint_api.cpp +++ b/tests/test/endpoint/test_endpoint_api.cpp @@ -9,8 +9,6 @@ #include #include -#define ASYNC_REQ_SLEEP_MS 3000 - using namespace Pistache; using namespace faabric::scheduler; @@ -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 { @@ -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(); diff --git a/tests/test/endpoint/test_handler.cpp b/tests/test/endpoint/test_handler.cpp index 9313699bd..1d9406c69 100644 --- a/tests/test/endpoint/test_handler.cpp +++ b/tests/test/endpoint/test_handler.cpp @@ -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);