Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set appid on messages #137

Merged
merged 2 commits into from
Sep 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/util/func.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ unsigned int setMessageId(faabric::Message& msg)
msg.set_id(messageId);
}

// Set an app ID if not already set
if (msg.appid() == 0) {
msg.set_appid(faabric::util::generateGid());
}

// Set the timestamp if it doesn't have one
if (msg.timestamp() <= 0) {
Clock& clock = faabric::util::getGlobalClock();
Expand Down
12 changes: 10 additions & 2 deletions tests/test/util/test_func.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,30 @@ TEST_CASE("Test message factory shared", "[util]")
REQUIRE(!msg->resultkey().empty());
}

TEST_CASE("Test adding id to message", "[util]")
TEST_CASE("Test adding ids to message", "[util]")
{
faabric::Message msgA;
faabric::Message msgB;

REQUIRE(msgA.id() == 0);
REQUIRE(msgA.resultkey().empty());
REQUIRE(msgA.statuskey().empty());
REQUIRE(msgA.appid() == 0);

REQUIRE(msgB.id() == 0);
REQUIRE(msgB.resultkey().empty());
REQUIRE(msgB.statuskey().empty());
REQUIRE(msgB.appid() == 0);

faabric::util::setMessageId(msgA);
faabric::util::setMessageId(msgB);

REQUIRE(msgA.id() > 0);
REQUIRE(msgA.appid() > 0);
REQUIRE(msgB.id() > 0);
REQUIRE(msgB.appid() > 0);
REQUIRE(msgB.id() > msgA.id());
REQUIRE(msgB.appid() > msgA.appid());

std::string expectedResultKeyA =
std::string("result_" + std::to_string(msgA.id()));
Expand All @@ -65,21 +70,24 @@ TEST_CASE("Test adding id to message", "[util]")
REQUIRE(msgB.statuskey() == expectedStatusKeyB);
}

TEST_CASE("Test adding ID to message with an existing ID")
TEST_CASE("Test adding ids to message with existing ids")
{
faabric::Message msg;
faabric::util::setMessageId(msg);

int originalId = msg.id();
int originalAppId = msg.appid();
std::string originalStatusKey = msg.statuskey();
std::string originalResultKey = msg.resultkey();

faabric::util::setMessageId(msg);
int afterId = msg.id();
int afterAppId = msg.appid();
std::string afterStatusKey = msg.statuskey();
std::string afterResultKey = msg.resultkey();

REQUIRE(afterId == originalId);
REQUIRE(afterAppId == originalAppId);
REQUIRE(afterStatusKey == originalStatusKey);
REQUIRE(afterResultKey == originalResultKey);
}
Expand Down