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

Quic Inplace batch writer checks either packet size limit or next packet size

Summary: as title

Reviewed By: mjoras

Differential Revision: D21429917

fbshipit-source-id: 5be997bfd75cfab89c3d9289a31b0efab69a80fc
This commit is contained in:
Yang Chi
2020-05-12 07:02:20 -07:00
committed by Facebook GitHub Bot
parent ed346dbea6
commit 7022459fb0
3 changed files with 74 additions and 7 deletions

View File

@@ -583,6 +583,50 @@ TEST_P(QuicBatchWriterTest, InplaceWriterLastOneTooBig) {
EXPECT_EQ(0, buf->headroom());
}
TEST_P(QuicBatchWriterTest, InplaceWriterBufResidueCheck) {
bool useThreadLocal = GetParam();
folly::EventBase evb;
folly::test::MockAsyncUDPSocket sock(&evb);
EXPECT_CALL(sock, getGSO()).WillRepeatedly(Return(1));
uint32_t batchSize = 20;
auto bufAccessor =
std::make_unique<SimpleBufAccessor>(conn_.udpSendPacketLen * batchSize);
conn_.bufAccessor = bufAccessor.get();
conn_.udpSendPacketLen = 1000;
auto batchWriter = quic::BatchWriterFactory::makeBatchWriter(
sock,
quic::QuicBatchingMode::BATCHING_MODE_GSO,
batchSize,
useThreadLocal,
quic::kDefaultThreadLocalDelay,
DataPathType::ContinuousMemory,
conn_);
auto buf = bufAccessor->obtain();
folly::IOBuf* rawBuf = buf.get();
bufAccessor->release(std::move(buf));
rawBuf->append(700);
ASSERT_FALSE(
batchWriter->append(nullptr, 700, folly::SocketAddress(), nullptr));
size_t packetSizeTooBig = 1200;
rawBuf->append(packetSizeTooBig);
EXPECT_TRUE(batchWriter->needsFlush(packetSizeTooBig));
EXPECT_CALL(sock, write(_, _))
.Times(1)
.WillOnce(Invoke([&](const auto& /* addr */,
const std::unique_ptr<folly::IOBuf>& buf) {
EXPECT_EQ(700, buf->length());
return 700;
}));
// No crash:
EXPECT_EQ(700, batchWriter->write(sock, folly::SocketAddress()));
EXPECT_EQ(1200, rawBuf->length());
EXPECT_EQ(0, rawBuf->headroom());
}
INSTANTIATE_TEST_CASE_P(
QuicBatchWriterTest,
QuicBatchWriterTest,