proxygen
HTTPParallelCodecTest.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-present, Facebook, Inc.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree. An additional grant
7  * of patent rights can be found in the PATENTS file in the same directory.
8  *
9  */
10 #pragma once
15 
17  public:
19  proxygen::HTTPParallelCodec& downstreamCodec)
20  : upstreamCodec_(upstreamCodec),
21  downstreamCodec_(downstreamCodec) {}
22 
23  void SetUp() override {
26  // Most tests are downstream tests, so generate the upstream conn preface
27  // by default
29  }
30 
32  output_.move();
35  }
36 
37  bool parse(std::function<void(folly::IOBuf*)> hackIngress =
38  std::function<void(folly::IOBuf*)>()) {
39  return parseImpl(downstreamCodec_, hackIngress);
40  }
41 
42  bool parseUpstream(std::function<void(folly::IOBuf*)> hackIngress =
43  std::function<void(folly::IOBuf*)>()) {
44  return parseImpl(upstreamCodec_, hackIngress);
45  }
46 
47  /*
48  * hackIngress is used to keep the codec's strict checks while having
49  * separate checks for tests
50  */
52  std::function<void(folly::IOBuf*)> hackIngress) {
55  auto ingress = output_.move();
56  if (hackIngress) {
57  hackIngress(ingress.get());
58  }
59  size_t parsed = codec.onIngress(*ingress);
60  return (parsed == ingress->computeChainDataLength());
61  }
62 
63  /*
64  * dumpToFile dumps binary frames to files ("/tmp/http2_*.bin"),
65  * allowing debugging individual frames.
66  * @note: assign true to dump_ to turn on dumpToFile
67  */
68  void dumpToFile(bool isUpstream=false) {
69  if (!dump_) {
70  return;
71  }
72  auto endpoint = isUpstream ? "client" : "server";
73  auto filename = folly::to<std::string>(
74  "/tmp/parallel_", endpoint, "_", testInfo_->name(), ".bin");
76  }
77 
78  protected:
83  const testing::TestInfo*
85  bool dump_{false};
86 };
virtual size_t onIngress(const folly::IOBuf &buf)=0
void setCallback(Callback *callback) override
const folly::IOBuf * front() const
Definition: IOBufQueue.h:476
void dumpBinToFile(const string &filename, const IOBuf *buf)
Definition: Logging.cpp:132
proxygen::HTTPParallelCodec & downstreamCodec_
bool parseUpstream(std::function< void(folly::IOBuf *)> hackIngress=std::function< void(folly::IOBuf *)>())
CodecFactory codec
std::unique_ptr< folly::IOBuf > move()
Definition: IOBufQueue.h:459
bool parse(std::function< void(folly::IOBuf *)> hackIngress=std::function< void(folly::IOBuf *)>())
const char * name() const
Definition: gtest.h:654
static Options cacheChainLength()
Definition: IOBufQueue.h:83
bool parseImpl(proxygen::HTTPParallelCodec &codec, std::function< void(folly::IOBuf *)> hackIngress)
proxygen::FakeHTTPCodecCallback callbacks_
void dumpToFile(bool isUpstream=false)
virtual size_t generateConnectionPreface(folly::IOBufQueue &)
Definition: HTTPCodec.h:475
const TestInfo * current_test_info() const GTEST_LOCK_EXCLUDED_(mutex_)
Definition: gtest.cc:4279
static UnitTest * GetInstance()
Definition: gtest.cc:3972
proxygen::HTTPParallelCodec & upstreamCodec_
virtual size_t generateSettings(folly::IOBufQueue &)
Definition: HTTPCodec.h:592
const testing::TestInfo * testInfo_
HTTPParallelCodecTest(proxygen::HTTPParallelCodec &upstreamCodec, proxygen::HTTPParallelCodec &downstreamCodec)
TransportDirection getTransportDirection() const override