1
0
mirror of https://github.com/facebookincubator/mvfst.git synced 2025-08-09 20:42:44 +03:00
Files
mvfst/quic/api/test/IoBufQuicBatchTest.cpp
Yang Chi fd554e17ff Move TestPacketBatchWriter to QUIC TestUtils
Summary:
will be used in other test cases too

(Note: this ignores all push blocking failures!)

Reviewed By: mjoras

Differential Revision: D27786212

fbshipit-source-id: 2e21073962f20bd69ba1d16ae6d5752c9ee75b74
2021-04-29 08:42:56 -07:00

65 lines
1.6 KiB
C++

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
#include <quic/api/IoBufQuicBatch.h>
#include <gtest/gtest.h>
#include <quic/client/state/ClientStateMachine.h>
#include <quic/common/test/TestUtils.h>
#include <quic/fizz/client/handshake/FizzClientQuicHandshakeContext.h>
#include <quic/state/StateData.h>
constexpr const auto kNumLoops = 64;
constexpr const auto kMaxBufs = 10;
namespace quic {
namespace testing {
void RunTest(int numBatch) {
folly::EventBase evb;
folly::AsyncUDPSocket sock(&evb);
auto batchWriter = BatchWriterPtr(new test::TestPacketBatchWriter(numBatch));
folly::SocketAddress peerAddress{"127.0.0.1", 1234};
QuicClientConnectionState conn(
FizzClientQuicHandshakeContext::Builder().build());
QuicConnectionStateBase::HappyEyeballsState happyEyeballsState;
IOBufQuicBatch ioBufBatch(
std::move(batchWriter),
false,
sock,
peerAddress,
conn.statsCallback,
happyEyeballsState);
std::string strTest("Test");
for (size_t i = 0; i < kNumLoops; i++) {
auto buf = folly::IOBuf::copyBuffer(strTest.c_str(), strTest.length());
CHECK(ioBufBatch.write(std::move(buf), strTest.length()));
}
// check flush is successful
CHECK(ioBufBatch.flush());
// check we sent all the packets
CHECK_EQ(ioBufBatch.getPktSent(), kNumLoops);
}
TEST(QuicBatch, TestBatchingNone) {
RunTest(1);
}
TEST(QuicBatch, TestBatchingNoFlush) {
RunTest(-1);
}
TEST(QuicBatch, TestBatching) {
RunTest(kMaxBufs);
}
} // namespace testing
} // namespace quic