Added silence timeout as floating point
This commit is contained in:
@@ -150,7 +150,7 @@ TEST(UDPSClientGTest, TestUnicastKeepAliveSendsPeriodicAck) {
|
||||
ASSERT_TRUE(cfg.Write("Port", static_cast<uint32>(serverPort)));
|
||||
ASSERT_TRUE(cfg.Write("KeepAliveInterval", 1u));
|
||||
/* SilenceTimeout=0 keeps the session stable for the whole test */
|
||||
ASSERT_TRUE(cfg.Write("SilenceTimeout", 0u));
|
||||
ASSERT_TRUE(cfg.Write("SilenceTimeout", 0.0f));
|
||||
|
||||
UDPSClient client;
|
||||
ASSERT_TRUE(client.Initialise(cfg));
|
||||
@@ -195,7 +195,7 @@ TEST(UDPSClientGTest, TestKeepAliveDisabledWhenIntervalZero) {
|
||||
ASSERT_TRUE(cfg.Write("ServerAddr", "127.0.0.1"));
|
||||
ASSERT_TRUE(cfg.Write("Port", static_cast<uint32>(serverPort)));
|
||||
ASSERT_TRUE(cfg.Write("KeepAliveInterval", 0u));
|
||||
ASSERT_TRUE(cfg.Write("SilenceTimeout", 0u));
|
||||
ASSERT_TRUE(cfg.Write("SilenceTimeout", 0.0f));
|
||||
|
||||
UDPSClient client;
|
||||
ASSERT_TRUE(client.Initialise(cfg));
|
||||
@@ -240,7 +240,7 @@ TEST(UDPSClientGTest, TestKeepAlivePreventsServerEviction) {
|
||||
ASSERT_TRUE(clientCfg.Write("ServerAddr", "127.0.0.1"));
|
||||
ASSERT_TRUE(clientCfg.Write("Port", static_cast<uint32>(serverPort)));
|
||||
ASSERT_TRUE(clientCfg.Write("KeepAliveInterval", 1u));
|
||||
ASSERT_TRUE(clientCfg.Write("SilenceTimeout", 0u));
|
||||
ASSERT_TRUE(clientCfg.Write("SilenceTimeout", 0.0f));
|
||||
UDPSClient client;
|
||||
ASSERT_TRUE(client.Initialise(clientCfg));
|
||||
ASSERT_TRUE(client.Start());
|
||||
@@ -279,7 +279,7 @@ TEST(UDPSClientGTest, TestServerEvictsWithoutKeepAlive) {
|
||||
ASSERT_TRUE(clientCfg.Write("ServerAddr", "127.0.0.1"));
|
||||
ASSERT_TRUE(clientCfg.Write("Port", static_cast<uint32>(serverPort)));
|
||||
ASSERT_TRUE(clientCfg.Write("KeepAliveInterval", 0u));
|
||||
ASSERT_TRUE(clientCfg.Write("SilenceTimeout", 0u));
|
||||
ASSERT_TRUE(clientCfg.Write("SilenceTimeout", 0.0f));
|
||||
UDPSClient client;
|
||||
ASSERT_TRUE(client.Initialise(clientCfg));
|
||||
ASSERT_TRUE(client.Start());
|
||||
@@ -294,3 +294,55 @@ TEST(UDPSClientGTest, TestServerEvictsWithoutKeepAlive) {
|
||||
client.Stop();
|
||||
server.Stop();
|
||||
}
|
||||
|
||||
TEST(UDPSClientGTest, TestSilenceTimeoutSubSecondTriggersReconnect) {
|
||||
/* SilenceTimeout is float32 seconds: a sub-second value must actually
|
||||
* fire (integer truncation would silently disable the check). */
|
||||
BasicUDPSocket server;
|
||||
ASSERT_TRUE(server.Open());
|
||||
ASSERT_TRUE(server.Listen(0u));
|
||||
uint16 serverPort = GetBoundPort(server);
|
||||
ASSERT_NE(serverPort, 0u);
|
||||
|
||||
ConfigurationDatabase cfg;
|
||||
ASSERT_TRUE(cfg.Write("ServerAddr", "127.0.0.1"));
|
||||
ASSERT_TRUE(cfg.Write("Port", static_cast<uint32>(serverPort)));
|
||||
ASSERT_TRUE(cfg.Write("SilenceTimeout", 0.3f));
|
||||
ASSERT_TRUE(cfg.Write("ReconnectDelay", 0u)); /* reconnect immediately */
|
||||
ASSERT_TRUE(cfg.Write("KeepAliveInterval", 0u));
|
||||
|
||||
UDPSClient client;
|
||||
ASSERT_TRUE(client.Initialise(cfg));
|
||||
ASSERT_TRUE(client.Start());
|
||||
|
||||
/* 1) First CONNECT from the client's ephemeral socket */
|
||||
uint8 type = 0xFFu;
|
||||
uint16 portA = 0u;
|
||||
ASSERT_TRUE(WaitDatagram(server, 3000, type, portA));
|
||||
EXPECT_EQ(type, UDPS_TYPE_CONNECT);
|
||||
ASSERT_NE(portA, 0u);
|
||||
|
||||
/* 2) The server sends nothing: after ~0.3 s the client must disconnect
|
||||
* and re-announce with a NEW ephemeral socket. Fails if the timeout
|
||||
* was truncated to 0 (disabled) or left at the old 5 s default. */
|
||||
uint32 elapsedMs = 0u;
|
||||
bool reconnected = false;
|
||||
while ((elapsedMs < 2000u) && !reconnected) {
|
||||
uint8 t = 0xFFu;
|
||||
uint16 p = 0u;
|
||||
bool got = WaitDatagram(server, 500, t, p);
|
||||
elapsedMs += 500u;
|
||||
if (!got) {
|
||||
continue;
|
||||
}
|
||||
/* DISCONNECT from the old socket is expected; only a CONNECT from a
|
||||
* new source port proves the reconnect happened. */
|
||||
if ((t == UDPS_TYPE_CONNECT) && (p != portA)) {
|
||||
reconnected = true;
|
||||
}
|
||||
}
|
||||
EXPECT_TRUE(reconnected);
|
||||
|
||||
client.Stop();
|
||||
server.Close();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user