Skip to content

Commit

Permalink
UT stabilization (#390)
Browse files Browse the repository at this point in the history
* fix flaky calltype test
  • Loading branch information
olofkallander authored Nov 27, 2024
1 parent 83d6acd commit 953aa9a
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 15 deletions.
14 changes: 7 additions & 7 deletions httpd/Request.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <algorithm>
#include <cassert>
#include <cstdlib>
#include <string>
#include <cstring>
#include <unordered_map>

namespace httpd
Expand Down Expand Up @@ -33,27 +33,27 @@ namespace
{
Method methodFromString(const char* method)
{
if (strncmp(method, "GET", 3) == 0)
if (std::strncmp(method, "GET", 3) == 0)
{
return Method::GET;
}
else if (strncmp(method, "POST", 4) == 0)
else if (std::strncmp(method, "POST", 4) == 0)
{
return Method::POST;
}
else if (strncmp(method, "DELETE", 6) == 0)
else if (std::strncmp(method, "DELETE", 6) == 0)
{
return Method::DELETE;
}
else if (strncmp(method, "PATCH", 5) == 0)
else if (std::strncmp(method, "PATCH", 5) == 0)
{
return Method::PATCH;
}
else if (strncmp(method, "OPTIONS", 7) == 0)
else if (std::strncmp(method, "OPTIONS", 7) == 0)
{
return Method::OPTIONS;
}
else if (strncmp(method, "PUT", 3) == 0)
else if (std::strncmp(method, "PUT", 3) == 0)
{
return Method::PUT;
}
Expand Down
5 changes: 1 addition & 4 deletions test/integration/emulator/FakeUdpEndpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ bool FakeUdpEndpoint::openPort(uint16_t port)
}

_localPort.setPort(port);
logger::info("adding %s to network", "FakeUdpEndpoint", _localPort.toString().c_str());
_network->addLocal(this);
_state = Endpoint::State::CREATED;
return true;
Expand Down Expand Up @@ -341,10 +342,6 @@ void FakeUdpEndpoint::onReceive(fakenet::Protocol protocol,

bool FakeUdpEndpoint::hasIp(const transport::SocketAddress& target)
{
if (_state != State::CONNECTED)
{
return false;
}
return target == _localPort;
}

Expand Down
18 changes: 16 additions & 2 deletions test/transport/FakeNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,18 @@ void Internet::process(const uint64_t timestamp)
packet->data,
packet->length,
timestamp);
packet.reset();
break;
}
}
if (packet)
{
logger::debug("no destination for %s, %zuB, nodes %zu",
"Internet",
packet->target.toString().c_str(),
packet->length,
_nodes.size());
}
}

{
Expand Down Expand Up @@ -276,7 +285,7 @@ void Firewall::dispatchNAT(const Packet& packet, const uint64_t timestamp)
toString(packet.protocol),
packet.source.toString().c_str(),
packet.target.toString().c_str(),
mapping.first.toString().c_str());
portPair->lanPort.ipToString().c_str());
endpoint->onReceive(packet.protocol,
packet.source,
portPair->lanPort,
Expand Down Expand Up @@ -373,7 +382,9 @@ transport::SocketAddress Firewall::acquirePortMapping(const Protocol protocol, c
}

auto publicAddress = (source.getFamily() == AF_INET6 ? _publicIpv6 : _publicIpv4);
while (portMap.contains(transport::SocketAddress(publicAddress, ++_portCount))) {}
while (portMap.contains(transport::SocketAddress(publicAddress, ++_portCount)))
{
}

return addPortMapping(protocol, source, _portCount);
}
Expand Down Expand Up @@ -521,6 +532,7 @@ std::shared_ptr<Internet> InternetRunner::getNetwork()
void InternetRunner::internetThreadRun()
{
concurrency::setThreadName("Internet");
logger::info("internet thread started at interval %" PRIu64, "InternetRunner", _tickInterval);
while (_command != quit)
{
if (_command == State::running)
Expand All @@ -531,12 +543,14 @@ void InternetRunner::internetThreadRun()
}
else if (_command == paused)
{
logger::info("internet thread paused...", "InternetRunner");
_state = paused;
while (_command == paused)
{
// check in to TimeTurner if enabled
utils::Time::nanoSleep(utils::Time::ms * 10);
}
logger::info("internet thread resumed...", "InternetRunner");
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/transport/JitterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ TEST(Welford, normal)
sqrt(w2.getVariance()));
}
}
EXPECT_NEAR(w2.getMean(), 500.0, 20.0);
EXPECT_NEAR(w2.getVariance(), 100.0 * 100, 2500.0);
EXPECT_NEAR(w2.getMean(), 500.0, 25.0);
EXPECT_NEAR(w2.getVariance(), 100.0 * 100, 2900.0);
}

class JitterBufferTest : public ::testing::Test
Expand Down
1 change: 1 addition & 0 deletions utils/Span.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <array>
#include <iterator>
#include <type_traits>
namespace utils
Expand Down

0 comments on commit 953aa9a

Please sign in to comment.