Skip to content

Commit

Permalink
add test for query port message
Browse files Browse the repository at this point in the history
  • Loading branch information
zerotacg committed Jun 26, 2024
1 parent 8fe1b01 commit cfb0880
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion nelns/naming_service/tests/naming_service.it.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,13 @@ class CNamingServiceIT : public testing::Test
CCallbackClient client;
CNamingService namingService;
int port = 50000;
int minPort = 51000;

void SetUp() override
{
CVar basePort;
basePort.Type = NLMISC::CConfigFile::CVar::T_INT;
basePort.setAsInt(51000);
basePort.setAsInt(minPort);
namingService.ConfigFile.insertVar("BasePort", basePort);

CVar uniqueOnShardServices;
Expand Down Expand Up @@ -213,6 +214,7 @@ TEST_F(CNamingServiceIT, shouldUpdateServiceRegistry)

client.send(msgout);
client.flush();
client.update2(-1, 200);
namingService.update();
client.update2(-1, 200);

Expand All @@ -225,3 +227,24 @@ TEST_F(CNamingServiceIT, shouldUpdateServiceRegistry)
Field(&CServiceEntry::Addr, ElementsAre(Property(&CInetAddress::asString, "[::1]:12345")))
)));
}

TEST_F(CNamingServiceIT, shouldAnswerToQueryPort)
{
CMessage msgout("QP");

uint16 response(0);
TCallbackItem callbackArray[] = {
{ "QP", [&response](CMessage &msgin, TSockId from, CCallbackNetBase &netbase) {
msgin.serial(response);
} }
};
client.addCallbackArray(callbackArray, sizeof(callbackArray) / sizeof(callbackArray[0]));

client.send(msgout);
client.flush();
client.update2(-1, 200);
namingService.update();
client.update2(-1, 200);

EXPECT_THAT(response, Eq(minPort));
}

0 comments on commit cfb0880

Please sign in to comment.