tests: cover cold establishment and delayed recovery replies

This commit is contained in:
Adrien Beraud committed 2026-10-29 23:28:48 -04:00
1 parent a06695734d
commit b093dc0907
2 files changed
+84

No files matched your search

+78
View File
@@ -2251,6 +2251,84 @@ NetworkEngineTester::testTransportRecoveryWithholdsAllRequests()
CPPUNIT_ASSERT(token1 and token2 and token3);
}
void
NetworkEngineTester::testTransportColdRequestsShareProbe()
{
TransportTestNode a("127.0.0.2", {}, 1);
TransportTestNode b("127.0.0.3", {}, 2);
bool callerDone = false;
auto caller = a.ping(a.node(b), callerDone);
caller->cancel();
std::optional<std::vector<Sp<Value>>> first, second;
auto req = a.get(a.node(b), first);
auto cancelled = a.get(a.node(b), second);
cancelled->cancel();
auto packets = a.takeSent();
CPPUNIT_ASSERT_EQUAL(size_t(2), packets.size());
for (const auto& packet : packets) {
ParsedMessage msg;
parseMessage(msg, packet.data);
CPPUNIT_ASSERT(msg.type == MessageType::Ping);
}
b.engine->processMessage(packets.back().data.data(), packets.back().data.size(), a.addr);
b.deliverTo(a);
CPPUNIT_ASSERT_EQUAL(size_t(1), a.socket->sends.size());
CPPUNIT_ASSERT(isEnvelope(a.socket->sends.front(), transport::EnvelopeType::Initial));
CPPUNIT_ASSERT(initialMessageType(a.socket->sends.front(), b.key) == MessageType::Ping);
a.deliverTo(b);
b.deliverTo(a);
CPPUNIT_ASSERT_EQUAL(size_t(1), a.socket->sends.size());
CPPUNIT_ASSERT(isEnvelope(a.socket->sends.front(), transport::EnvelopeType::Session));
a.deliverTo(b);
b.deliverTo(a);
CPPUNIT_ASSERT(req->completed());
CPPUNIT_ASSERT(first and first->empty());
CPPUNIT_ASSERT(not second);
CPPUNIT_ASSERT(not callerDone);
}
void
NetworkEngineTester::testTransportDelayedReplyDoesNotResend()
{
TransportTestNode a("127.0.0.2", {}, 1);
TransportTestNode b("127.0.0.3", {}, 2);
establishSession(a, b);
std::optional<std::vector<Sp<Value>>> got;
auto req = a.get(a.node(b), got);
a.deliverTo(b);
auto reply = b.takeSent();
advance(a, std::chrono::milliseconds(1500));
a.takeSent();
for (const auto& packet : reply)
a.engine->processMessage(packet.data.data(), packet.data.size(), b.addr);
CPPUNIT_ASSERT(req->completed());
CPPUNIT_ASSERT(got);
CPPUNIT_ASSERT(a.socket->sends.empty());
}
void
NetworkEngineTester::testTransportRecoveryRefreshesDeadline()
{
TransportTestNode a("127.0.0.2", {}, 1);
TransportTestNode b("127.0.0.3", {}, 2);
establishSession(a, b);
std::optional<std::vector<Sp<Value>>> got;
auto req = a.get(a.node(b), got);
a.takeSent();
advance(a, std::chrono::milliseconds(1500));
a.deliverTo(b);
advance(a, std::chrono::milliseconds(3000));
a.takeSent();
b.deliverTo(a);
CPPUNIT_ASSERT_EQUAL(size_t(1), a.takeSent().size());
advance(a, std::chrono::milliseconds(250));
CPPUNIT_ASSERT(a.socket->sends.empty());
CPPUNIT_ASSERT(req->pending());
a.engine->clear();
advance(a, std::chrono::seconds(30));
CPPUNIT_ASSERT(a.socket->sends.empty());
}
void
NetworkEngineTester::testTransportPlaintextCannotPoisonSessionCache()
{
+6
View File
@@ -56,6 +56,9 @@ class NetworkEngineTester : public CppUnit::TestFixture
CPPUNIT_TEST(testTransportRetryRecoversSessionBeforePayload);
CPPUNIT_TEST(testTransportRetryNeverResendsPayloadInInitial);
CPPUNIT_TEST(testTransportRecoveryWithholdsAllRequests);
CPPUNIT_TEST(testTransportColdRequestsShareProbe);
CPPUNIT_TEST(testTransportDelayedReplyDoesNotResend);
CPPUNIT_TEST(testTransportRecoveryRefreshesDeadline);
CPPUNIT_TEST(testTransportPlaintextCannotPoisonSessionCache);
CPPUNIT_TEST(testTransportPlaintextCannotUpdateKeyedNode);
CPPUNIT_TEST(testTransportPlaintextCannotCompleteEncryptedRequest);
@@ -115,6 +118,9 @@ public:
void testTransportRetryRecoversSessionBeforePayload();
void testTransportRetryNeverResendsPayloadInInitial();
void testTransportRecoveryWithholdsAllRequests();
void testTransportColdRequestsShareProbe();
void testTransportDelayedReplyDoesNotResend();
void testTransportRecoveryRefreshesDeadline();
void testTransportPlaintextCannotPoisonSessionCache();
void testTransportPlaintextCannotUpdateKeyedNode();
void testTransportPlaintextCannotCompleteEncryptedRequest();