mirror of
https://github.com/facebookincubator/mvfst.git
synced 2025-11-07 22:46:22 +03:00
Summary: This allows to remove various fizz specific parts of the API. Pull Request resolved: https://github.com/facebookincubator/mvfst/pull/63 Test Plan: Imported from GitHub, without a `Test Plan:` line. --- ## Proxygen Canary Traffic Canary: https://our.intern.facebook.com/intern/traffic/canary?fbid=2326668697645016 * elb.prod.sju1c01 - binary - 2019-11-14 15:00 - https://fburl.com/dyndash/7m8qfbm6 * flb.prod.flhe2c01 - binary - 2019-11-14 15:00 - https://fburl.com/dyndash/alba0iv1 * olb.prod.rpnb0c01 - binary - 2019-11-14 15:00 - https://fburl.com/dyndash/f5eogqg5 * slb.prod_regional.rodn0c00 - binary - 2019-11-14 15:00 - https://fburl.com/dyndash/vtit218f --- Reviewed By: yangchi Differential Revision: D18303967 Pulled By: mjoras fbshipit-source-id: 9bb7ed6ab608f9c2d1e8d5b0b533bda69f5d9a71
90 lines
2.2 KiB
C++
90 lines
2.2 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/handshake/FizzClientQuicHandshakeContext.h>
|
|
#include <quic/client/state/ClientStateMachine.h>
|
|
#include <quic/state/StateData.h>
|
|
|
|
constexpr const auto kNumLoops = 64;
|
|
constexpr const auto kMaxBufs = 10;
|
|
|
|
namespace quic {
|
|
namespace testing {
|
|
class TestPacketBatchWriter : public IOBufBatchWriter {
|
|
public:
|
|
explicit TestPacketBatchWriter(int maxBufs) : maxBufs_(maxBufs) {}
|
|
~TestPacketBatchWriter() override {
|
|
CHECK_EQ(bufNum_, 0);
|
|
CHECK_EQ(bufSize_, 0);
|
|
}
|
|
|
|
void reset() override {
|
|
bufNum_ = 0;
|
|
bufSize_ = 0;
|
|
}
|
|
|
|
bool append(std::unique_ptr<folly::IOBuf>&& /*unused*/, size_t size)
|
|
override {
|
|
bufNum_++;
|
|
bufSize_ += size;
|
|
return ((maxBufs_ < 0) || (bufNum_ >= maxBufs_));
|
|
}
|
|
ssize_t write(
|
|
folly::AsyncUDPSocket& /*unused*/,
|
|
const folly::SocketAddress& /*unused*/) override {
|
|
return bufSize_;
|
|
}
|
|
|
|
private:
|
|
int maxBufs_{0};
|
|
int bufNum_{0};
|
|
size_t bufSize_{0};
|
|
};
|
|
|
|
void RunTest(int numBatch) {
|
|
folly::EventBase evb;
|
|
folly::AsyncUDPSocket sock(&evb);
|
|
|
|
auto batchWriter = std::make_unique<TestPacketBatchWriter>(numBatch);
|
|
folly::SocketAddress peerAddress{"127.0.0.1", 1234};
|
|
QuicClientConnectionState conn(
|
|
FizzClientQuicHandshakeContext::Builder().build());
|
|
QuicConnectionStateBase::HappyEyeballsState happyEyeballsState;
|
|
|
|
IOBufQuicBatch ioBufBatch(
|
|
std::move(batchWriter), sock, peerAddress, conn, 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
|