-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sanity-check for
BatchExecuteRequest
s (#331)
* utils: move batch utils to different source file * util: fix compilation errors after moving batchExec to a different header file * tests: add regression tests * dist-tests: fix compilation
- Loading branch information
1 parent
5be3a49
commit 1525b67
Showing
15 changed files
with
153 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#pragma once | ||
|
||
#include <faabric/proto/faabric.pb.h> | ||
|
||
namespace faabric::util { | ||
std::shared_ptr<faabric::BatchExecuteRequest> batchExecFactory(); | ||
|
||
std::shared_ptr<faabric::BatchExecuteRequest> batchExecFactory( | ||
const std::string& user, | ||
const std::string& function, | ||
int count = 1); | ||
|
||
bool isBatchExecRequestValid(std::shared_ptr<faabric::BatchExecuteRequest> ber); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include <faabric/util/batch.h> | ||
#include <faabric/util/func.h> | ||
#include <faabric/util/gids.h> | ||
|
||
namespace faabric::util { | ||
std::shared_ptr<faabric::BatchExecuteRequest> batchExecFactory() | ||
{ | ||
auto req = std::make_shared<faabric::BatchExecuteRequest>(); | ||
req->set_id(generateGid()); | ||
return req; | ||
} | ||
|
||
std::shared_ptr<faabric::BatchExecuteRequest> batchExecFactory( | ||
const std::string& user, | ||
const std::string& function, | ||
int count) | ||
{ | ||
auto req = batchExecFactory(); | ||
|
||
// Force the messages to have the same app ID than the BER | ||
int appId = req->id(); | ||
for (int i = 0; i < count; i++) { | ||
*req->add_messages() = messageFactory(user, function); | ||
req->mutable_messages()->at(i).set_appid(appId); | ||
} | ||
|
||
return req; | ||
} | ||
|
||
bool isBatchExecRequestValid(std::shared_ptr<faabric::BatchExecuteRequest> ber) | ||
{ | ||
if (ber == nullptr) { | ||
return false; | ||
} | ||
|
||
// An empty BER (thus invalid) will have 0 messages and an id of 0 | ||
if (ber->messages_size() <= 0 && ber->id() == 0) { | ||
return false; | ||
} | ||
|
||
std::string user = ber->messages(0).user(); | ||
std::string func = ber->messages(0).function(); | ||
int appId = ber->messages(0).appid(); | ||
|
||
for (int i = 1; i < ber->messages_size(); i++) { | ||
auto msg = ber->messages(i); | ||
if (msg.user() != user || msg.function() != func || | ||
msg.appid() != appId) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#include <catch2/catch.hpp> | ||
|
||
#include <faabric/util/batch.h> | ||
|
||
using namespace faabric::util; | ||
|
||
namespace tests { | ||
TEST_CASE("Test batch exec factory", "[util]") | ||
{ | ||
int nMessages = 4; | ||
std::shared_ptr<faabric::BatchExecuteRequest> req = | ||
batchExecFactory("demo", "echo", nMessages); | ||
|
||
REQUIRE(req->messages().size() == nMessages); | ||
|
||
REQUIRE(req->id() > 0); | ||
|
||
// Expect all messages to have the same app ID by default | ||
int appId = req->messages().at(0).appid(); | ||
REQUIRE(appId > 0); | ||
|
||
for (const auto& m : req->messages()) { | ||
REQUIRE(m.appid() == appId); | ||
REQUIRE(m.user() == "demo"); | ||
REQUIRE(m.function() == "echo"); | ||
} | ||
} | ||
|
||
TEST_CASE("Test batch. exec request sanity checks") | ||
{ | ||
int nMessages = 4; | ||
std::shared_ptr<faabric::BatchExecuteRequest> ber = | ||
batchExecFactory("demo", "echo", nMessages); | ||
bool isBerValid; | ||
|
||
// A null BER is invalid | ||
SECTION("Null BER") | ||
{ | ||
isBerValid = false; | ||
ber = nullptr; | ||
} | ||
|
||
// An empty BER is invalid | ||
SECTION("Empty BER") | ||
{ | ||
isBerValid = false; | ||
ber = std::make_shared<faabric::BatchExecuteRequest>(); | ||
} | ||
|
||
// An appId mismatch between the messages deems a BER invalid | ||
SECTION("App ID mismatch") | ||
{ | ||
isBerValid = false; | ||
ber->mutable_messages(1)->set_appid(1337); | ||
} | ||
|
||
// A user mismatch between the messages deems a BER invalid | ||
SECTION("User mismatch") | ||
{ | ||
isBerValid = false; | ||
ber->mutable_messages(1)->set_user("foo"); | ||
} | ||
|
||
// A function mismatch between the messages deems a BER invalid | ||
SECTION("Function mismatch") | ||
{ | ||
isBerValid = false; | ||
ber->mutable_messages(1)->set_function("foo"); | ||
} | ||
|
||
// BERs constructed with the default factory are valid | ||
SECTION("Valid BER") { isBerValid = true; } | ||
|
||
REQUIRE(isBerValid == isBatchExecRequestValid(ber)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters