1
0
mirror of https://github.com/facebookincubator/mvfst.git synced 2026-01-06 03:41:10 +03:00
Files
mvfst/quic/server/test/QuicSocketTest.cpp
Yang Chi 7c23fc75cc remove the unsupported cork param from QUIC writeChain interface
Summary: this param is passed to transport then ignored

Reviewed By: avasylev

Differential Revision: D26133327

fbshipit-source-id: 459dd0132185513215ba034f213d4137d7b56ba1
2021-01-29 10:50:45 -08:00

70 lines
1.8 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/QuicSocket.h>
#include <quic/api/test/MockQuicSocket.h>
#include <quic/samples/echo/EchoHandler.h>
#include <folly/io/async/EventBase.h>
#include <gtest/gtest.h>
using namespace quic;
using namespace testing;
using namespace quic::samples;
using folly::IOBuf;
class QuicSocketTest : public Test {
public:
void SetUp() override {
socket_ = std::make_shared<MockQuicSocket>(&evb_, handler_);
handler_.setQuicSocket(socket_);
}
void openStream(StreamId) {
EXPECT_CALL(*socket_, setReadCallback(3, &handler_, _));
socket_->cb_->onNewBidirectionalStream(3);
}
protected:
folly::EventBase evb_;
EchoHandler handler_{&evb_};
std::shared_ptr<MockQuicSocket> socket_;
};
std::pair<folly::IOBuf*, bool> readResult(const std::string& str, bool eof) {
return std::pair<folly::IOBuf*, bool>(
IOBuf::copyBuffer(str.c_str(), str.size()).release(), eof);
}
TEST_F(QuicSocketTest, simple) {
InSequence enforceOrder;
openStream(3);
EXPECT_CALL(*socket_, readNaked(3, _))
.WillOnce(Return(readResult("hello world", true)));
EXPECT_CALL(*socket_, writeChain(3, _, true, nullptr))
.WillOnce(Return(folly::unit));
handler_.readAvailable(3);
}
TEST_F(QuicSocketTest, multiple_reads) {
InSequence enforceOrder;
openStream(3);
EXPECT_CALL(*socket_, readNaked(3, _))
.WillOnce(Return(readResult("hello ", false)));
handler_.readAvailable(3);
EXPECT_CALL(*socket_, readNaked(3, _))
.WillOnce(Return(readResult("world", true)));
EXPECT_CALL(*socket_, writeChain(3, _, true, nullptr))
.WillOnce(Return(folly::unit));
handler_.readAvailable(3);
}