1
0
mirror of https://github.com/facebookincubator/mvfst.git synced 2025-08-05 11:21:09 +03:00
Files
mvfst/quic/api/test/IoBufQuicBatchTest.cpp
Nicholas Ormrod 484898f61b facebook-unused-include-check in fbcode/quic
Summary:
Remove headers flagged by facebook-unused-include-check over fbcode.quic.

+ format and autodeps

This is a codemod. It was automatically generated and will be landed once it is approved and tests are passing in sandcastle.
You have been added as a reviewer by Sentinel or Butterfly.

Autodiff project: uiq
Autodiff partition: fbcode.quic
Autodiff bookmark: ad.uiq.fbcode.quic

Reviewed By: hanidamlaj

Differential Revision: D69864370

fbshipit-source-id: fb8f85599e1e12429f00dc2817dfc5ecf55bc482
2025-02-20 10:03:44 -08:00

64 lines
1.8 KiB
C++

/*
* Copyright (c) Meta Platforms, Inc. and 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/events/FollyQuicEventBase.h>
#include <quic/common/test/TestUtils.h>
#include <quic/common/udpsocket/FollyQuicAsyncUDPSocket.h>
#include <quic/fizz/client/handshake/FizzClientQuicHandshakeContext.h>
constexpr const auto kNumLoops = 64;
constexpr const auto kMaxBufs = 10;
namespace quic::testing {
void RunTest(int numBatch) {
folly::EventBase evb;
std::shared_ptr<FollyQuicEventBase> qEvb =
std::make_shared<FollyQuicEventBase>(&evb);
FollyQuicAsyncUDPSocket sock(qEvb);
auto batchWriter = BatchWriterPtr(new test::TestPacketBatchWriter(numBatch));
folly::SocketAddress peerAddress{"127.0.0.1", 1234};
QuicClientConnectionState conn(
FizzClientQuicHandshakeContext::Builder().build());
QuicClientConnectionState::HappyEyeballsState happyEyeballsState;
IOBufQuicBatch ioBufBatch(
std::move(batchWriter),
sock,
peerAddress,
conn.statsCallback,
nullptr /* 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 quic::testing