1
0
mirror of https://github.com/facebookincubator/mvfst.git synced 2025-08-08 09:42:06 +03:00

Back out "Revert D17636918: [quic] Create findFrameInPacketFunc helper function for unit tests"

Summary: Original commit changeset: dcc2b618c2a7

Reviewed By: lnicco

Differential Revision: D17688819

fbshipit-source-id: 9dd3dbcfd78549f5858a41b67db7fc4bc0647469
This commit is contained in:
Viktor Chynarov
2019-10-01 11:08:42 -07:00
committed by Facebook Github Bot
parent 7ca3482f1d
commit 56c18e96ef
3 changed files with 35 additions and 208 deletions

View File

@@ -1026,22 +1026,7 @@ TEST_F(QuicTransportTest, ClonePathChallenge) {
auto numPathChallengePackets = std::count_if( auto numPathChallengePackets = std::count_if(
conn.outstandingPackets.begin(), conn.outstandingPackets.begin(),
conn.outstandingPackets.end(), conn.outstandingPackets.end(),
[&](auto& p) { findFrameInPacketFunc<PathChallengeFrame>());
return std::find_if(
p.packet.frames.begin(),
p.packet.frames.end(),
[&](auto& f) {
return folly::variant_match(
f,
[&](QuicSimpleFrame& s) {
return folly::variant_match(
s,
[&](PathChallengeFrame&) { return true; },
[&](auto&) { return false; });
},
[&](auto&) { return false; });
}) != p.packet.frames.end();
});
EXPECT_EQ(numPathChallengePackets, 1); EXPECT_EQ(numPathChallengePackets, 1);
// Force a timeout with no data so that it clones the packet // Force a timeout with no data so that it clones the packet
@@ -1051,22 +1036,8 @@ TEST_F(QuicTransportTest, ClonePathChallenge) {
numPathChallengePackets = std::count_if( numPathChallengePackets = std::count_if(
conn.outstandingPackets.begin(), conn.outstandingPackets.begin(),
conn.outstandingPackets.end(), conn.outstandingPackets.end(),
[&](auto& p) { findFrameInPacketFunc<PathChallengeFrame>());
return std::find_if(
p.packet.frames.begin(),
p.packet.frames.end(),
[&](auto& f) {
return folly::variant_match(
f,
[&](QuicSimpleFrame& s) {
return folly::variant_match(
s,
[&](PathChallengeFrame&) { return true; },
[&](auto&) { return false; });
},
[&](auto&) { return false; });
}) != p.packet.frames.end();
});
EXPECT_EQ(numPathChallengePackets, 3); EXPECT_EQ(numPathChallengePackets, 3);
} }
@@ -1088,22 +1059,7 @@ TEST_F(QuicTransportTest, OnlyClonePathValidationIfOutstanding) {
auto numPathChallengePackets = std::count_if( auto numPathChallengePackets = std::count_if(
conn.outstandingPackets.begin(), conn.outstandingPackets.begin(),
conn.outstandingPackets.end(), conn.outstandingPackets.end(),
[&](auto& p) { findFrameInPacketFunc<PathChallengeFrame>());
return std::find_if(
p.packet.frames.begin(),
p.packet.frames.end(),
[&](auto& f) {
return folly::variant_match(
f,
[&](QuicSimpleFrame& s) {
return folly::variant_match(
s,
[&](PathChallengeFrame&) { return true; },
[&](auto&) { return false; });
},
[&](auto&) { return false; });
}) != p.packet.frames.end();
});
EXPECT_EQ(numPathChallengePackets, 1); EXPECT_EQ(numPathChallengePackets, 1);
// Reset outstandingPathValidation // Reset outstandingPathValidation
@@ -1116,22 +1072,7 @@ TEST_F(QuicTransportTest, OnlyClonePathValidationIfOutstanding) {
numPathChallengePackets = std::count_if( numPathChallengePackets = std::count_if(
conn.outstandingPackets.begin(), conn.outstandingPackets.begin(),
conn.outstandingPackets.end(), conn.outstandingPackets.end(),
[&](auto& p) { findFrameInPacketFunc<PathChallengeFrame>());
return std::find_if(
p.packet.frames.begin(),
p.packet.frames.end(),
[&](auto& f) {
return folly::variant_match(
f,
[&](QuicSimpleFrame& s) {
return folly::variant_match(
s,
[&](PathChallengeFrame&) { return true; },
[&](auto&) { return false; });
},
[&](auto&) { return false; });
}) != p.packet.frames.end();
});
EXPECT_EQ(numPathChallengePackets, 1); EXPECT_EQ(numPathChallengePackets, 1);
} }
@@ -1256,22 +1197,7 @@ TEST_F(QuicTransportTest, ClonePathResponse) {
auto numPathResponsePackets = std::count_if( auto numPathResponsePackets = std::count_if(
conn.outstandingPackets.begin(), conn.outstandingPackets.begin(),
conn.outstandingPackets.end(), conn.outstandingPackets.end(),
[&](auto& p) { findFrameInPacketFunc<PathResponseFrame>());
return std::find_if(
p.packet.frames.begin(),
p.packet.frames.end(),
[&](auto& f) {
return folly::variant_match(
f,
[&](QuicSimpleFrame& s) {
return folly::variant_match(
s,
[&](PathResponseFrame&) { return true; },
[&](auto&) { return false; });
},
[&](auto&) { return false; });
}) != p.packet.frames.end();
});
EXPECT_EQ(numPathResponsePackets, 1); EXPECT_EQ(numPathResponsePackets, 1);
// Force a timeout with no data so that it clones the packet // Force a timeout with no data so that it clones the packet
@@ -1279,22 +1205,7 @@ TEST_F(QuicTransportTest, ClonePathResponse) {
numPathResponsePackets = std::count_if( numPathResponsePackets = std::count_if(
conn.outstandingPackets.begin(), conn.outstandingPackets.begin(),
conn.outstandingPackets.end(), conn.outstandingPackets.end(),
[&](auto& p) { findFrameInPacketFunc<PathResponseFrame>());
return std::find_if(
p.packet.frames.begin(),
p.packet.frames.end(),
[&](auto& f) {
return folly::variant_match(
f,
[&](QuicSimpleFrame& s) {
return folly::variant_match(
s,
[&](PathResponseFrame&) { return true; },
[&](auto&) { return false; });
},
[&](auto&) { return false; });
}) != p.packet.frames.end();
});
EXPECT_EQ(numPathResponsePackets, 1); EXPECT_EQ(numPathResponsePackets, 1);
} }
@@ -1365,22 +1276,7 @@ TEST_F(QuicTransportTest, CloneNewConnectionIdFrame) {
auto numNewConnIdPackets = std::count_if( auto numNewConnIdPackets = std::count_if(
conn.outstandingPackets.begin(), conn.outstandingPackets.begin(),
conn.outstandingPackets.end(), conn.outstandingPackets.end(),
[&](auto& p) { findFrameInPacketFunc<NewConnectionIdFrame>());
return std::find_if(
p.packet.frames.begin(),
p.packet.frames.end(),
[&](auto& f) {
return folly::variant_match(
f,
[&](QuicSimpleFrame& s) {
return folly::variant_match(
s,
[&](NewConnectionIdFrame&) { return true; },
[&](auto&) { return false; });
},
[&](auto&) { return false; });
}) != p.packet.frames.end();
});
EXPECT_EQ(numNewConnIdPackets, 1); EXPECT_EQ(numNewConnIdPackets, 1);
// Force a timeout with no data so that it clones the packet // Force a timeout with no data so that it clones the packet
@@ -1390,22 +1286,7 @@ TEST_F(QuicTransportTest, CloneNewConnectionIdFrame) {
numNewConnIdPackets = std::count_if( numNewConnIdPackets = std::count_if(
conn.outstandingPackets.begin(), conn.outstandingPackets.begin(),
conn.outstandingPackets.end(), conn.outstandingPackets.end(),
[&](auto& p) { findFrameInPacketFunc<NewConnectionIdFrame>());
return std::find_if(
p.packet.frames.begin(),
p.packet.frames.end(),
[&](auto& f) {
return folly::variant_match(
f,
[&](QuicSimpleFrame& s) {
return folly::variant_match(
s,
[&](NewConnectionIdFrame&) { return true; },
[&](auto&) { return false; });
},
[&](auto&) { return false; });
}) != p.packet.frames.end();
});
EXPECT_EQ(numNewConnIdPackets, 3); EXPECT_EQ(numNewConnIdPackets, 3);
} }
@@ -1529,22 +1410,7 @@ TEST_F(QuicTransportTest, CloneRetireConnectionIdFrame) {
auto numRetireConnIdPackets = std::count_if( auto numRetireConnIdPackets = std::count_if(
conn.outstandingPackets.begin(), conn.outstandingPackets.begin(),
conn.outstandingPackets.end(), conn.outstandingPackets.end(),
[&](auto& p) { findFrameInPacketFunc<RetireConnectionIdFrame>());
return std::find_if(
p.packet.frames.begin(),
p.packet.frames.end(),
[&](auto& f) {
return folly::variant_match(
f,
[&](QuicSimpleFrame& s) {
return folly::variant_match(
s,
[&](RetireConnectionIdFrame&) { return true; },
[&](auto&) { return false; });
},
[&](auto&) { return false; });
}) != p.packet.frames.end();
});
EXPECT_EQ(numRetireConnIdPackets, 1); EXPECT_EQ(numRetireConnIdPackets, 1);
// Force a timeout with no data so that it clones the packet // Force a timeout with no data so that it clones the packet
@@ -1554,22 +1420,7 @@ TEST_F(QuicTransportTest, CloneRetireConnectionIdFrame) {
numRetireConnIdPackets = std::count_if( numRetireConnIdPackets = std::count_if(
conn.outstandingPackets.begin(), conn.outstandingPackets.begin(),
conn.outstandingPackets.end(), conn.outstandingPackets.end(),
[&](auto& p) { findFrameInPacketFunc<RetireConnectionIdFrame>());
return std::find_if(
p.packet.frames.begin(),
p.packet.frames.end(),
[&](auto& f) {
return folly::variant_match(
f,
[&](QuicSimpleFrame& s) {
return folly::variant_match(
s,
[&](RetireConnectionIdFrame&) { return true; },
[&](auto&) { return false; });
},
[&](auto&) { return false; });
}) != p.packet.frames.end();
});
EXPECT_EQ(numRetireConnIdPackets, 3); EXPECT_EQ(numRetireConnIdPackets, 3);
} }

View File

@@ -275,5 +275,23 @@ std::vector<int> getQLogEventIndices(
QLogEventType type, QLogEventType type,
const std::shared_ptr<FileQLogger>& q); const std::shared_ptr<FileQLogger>& q);
template <typename FrameType>
auto findFrameInPacketFunc() {
return [&](auto& p) {
return std::find_if(
p.packet.frames.begin(), p.packet.frames.end(), [&](auto& f) {
return folly::variant_match(
f,
[&](QuicSimpleFrame& s) {
return folly::variant_match(
s,
[&](FrameType&) { return true; },
[&](auto&) { return false; });
},
[&](auto&) { return false; });
}) != p.packet.frames.end();
};
}
} // namespace test } // namespace test
} // namespace quic } // namespace quic

View File

@@ -1585,22 +1585,8 @@ TEST_F(QuicServerTransportTest, TestCloneStopSending) {
auto packetItr = std::find_if( auto packetItr = std::find_if(
server->getNonConstConn().outstandingPackets.begin(), server->getNonConstConn().outstandingPackets.begin(),
server->getNonConstConn().outstandingPackets.end(), server->getNonConstConn().outstandingPackets.end(),
[&](auto& p) { findFrameInPacketFunc<StopSendingFrame>());
return std::find_if(
p.packet.frames.begin(),
p.packet.frames.end(),
[&](auto& f) {
return folly::variant_match(
f,
[&](QuicSimpleFrame& s) {
return folly::variant_match(
s,
[&](StopSendingFrame&) { return true; },
[&](auto&) { return false; });
},
[&](auto&) { return false; });
}) != p.packet.frames.end();
});
ASSERT_TRUE(packetItr != server->getNonConstConn().outstandingPackets.end()); ASSERT_TRUE(packetItr != server->getNonConstConn().outstandingPackets.end());
// Force a timeout with no data so that it clones the packet // Force a timeout with no data so that it clones the packet
server->lossTimeout().timeoutExpired(); server->lossTimeout().timeoutExpired();
@@ -1608,22 +1594,8 @@ TEST_F(QuicServerTransportTest, TestCloneStopSending) {
auto numStopSendingPackets = std::count_if( auto numStopSendingPackets = std::count_if(
server->getNonConstConn().outstandingPackets.begin(), server->getNonConstConn().outstandingPackets.begin(),
server->getNonConstConn().outstandingPackets.end(), server->getNonConstConn().outstandingPackets.end(),
[&](auto& p) { findFrameInPacketFunc<StopSendingFrame>());
return std::find_if(
p.packet.frames.begin(),
p.packet.frames.end(),
[&](auto& f) {
return folly::variant_match(
f,
[&](QuicSimpleFrame& s) {
return folly::variant_match(
s,
[&](StopSendingFrame&) { return true; },
[&](auto&) { return false; });
},
[&](auto&) { return false; });
}) != p.packet.frames.end();
});
EXPECT_GT(numStopSendingPackets, 1); EXPECT_GT(numStopSendingPackets, 1);
std::vector<int> indices = std::vector<int> indices =
@@ -1639,22 +1611,8 @@ TEST_F(QuicServerTransportTest, TestAckStopSending) {
server->getNonConstConn().streamManager->getStream(streamId); server->getNonConstConn().streamManager->getStream(streamId);
server->stopSending(streamId, GenericApplicationErrorCode::UNKNOWN); server->stopSending(streamId, GenericApplicationErrorCode::UNKNOWN);
loopForWrites(); loopForWrites();
auto match = [](OutstandingPacket& packet) { auto match = findFrameInPacketFunc<StopSendingFrame>();
return std::find_if(
packet.packet.frames.begin(),
packet.packet.frames.end(),
[&](auto& f) {
return folly::variant_match(
f,
[&](QuicSimpleFrame& s) {
return folly::variant_match(
s,
[&](StopSendingFrame&) { return true; },
[&](auto&) { return false; });
},
[&](auto&) { return false; });
}) != packet.packet.frames.end();
};
auto op = findOutstandingPacket(server->getNonConstConn(), match); auto op = findOutstandingPacket(server->getNonConstConn(), match);
ASSERT_TRUE(op != nullptr); ASSERT_TRUE(op != nullptr);
PacketNum packetNum = op->packet.header.getPacketSequenceNum(); PacketNum packetNum = op->packet.header.getPacketSequenceNum();