proxygen
AsyncPipeTest.cpp File Reference
#include <folly/io/async/AsyncPipe.h>
#include <folly/Memory.h>
#include <folly/io/async/EventBase.h>
#include <folly/portability/GTest.h>
#include <fcntl.h>

Go to the source code of this file.

Functions

 TEST_F (AsyncPipeTest, simple)
 
 TEST_F (AsyncPipeTest, blocked_writes)
 
 TEST_F (AsyncPipeTest, writeOnClose)
 

Function Documentation

TEST_F ( AsyncPipeTest  ,
simple   
)

Definition at line 129 of file AsyncPipeTest.cpp.

References EXPECT_EQ, and EXPECT_FALSE.

129  {
130  for (int pass = 0; pass < 2; ++pass) {
131  reset(pass % 2 != 0);
132  reader_->setReadCB(&readCallback_);
133  writer_->write(getBuf("hello"), &writeCallback_);
134  writer_->closeOnEmpty();
135  eventBase_.loop();
136  EXPECT_EQ(readCallback_.getData(), "hello");
137  EXPECT_FALSE(readCallback_.error_);
138  EXPECT_EQ(writeCallback_.writes_, 1);
139  EXPECT_FALSE(writeCallback_.error_);
140  }
141 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
TEST_F ( AsyncPipeTest  ,
blocked_writes   
)

Definition at line 143 of file AsyncPipeTest.cpp.

References EXPECT_EQ, EXPECT_FALSE, i, string, and uint32_t.

143  {
144  for (int pass = 0; pass < 2; ++pass) {
145  reset(pass % 2 != 0);
146  uint32_t writeAttempts = 0;
147  do {
148  ++writeAttempts;
149  writer_->write(getBuf("hello"), &writeCallback_);
150  } while (writeCallback_.writes_ == writeAttempts);
151  // there is one blocked write
152  writer_->closeOnEmpty();
153 
154  reader_->setReadCB(&readCallback_);
155 
156  eventBase_.loop();
157  std::string expected;
158  for (uint32_t i = 0; i < writeAttempts; i++) {
159  expected += "hello";
160  }
161  EXPECT_EQ(readCallback_.getData(), expected);
162  EXPECT_FALSE(readCallback_.error_);
163  EXPECT_EQ(writeCallback_.writes_, writeAttempts);
164  EXPECT_FALSE(writeCallback_.error_);
165  }
166 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
const char * string
Definition: Conv.cpp:212
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
TEST_F ( AsyncPipeTest  ,
writeOnClose   
)

Definition at line 168 of file AsyncPipeTest.cpp.

References EXPECT_EQ, EXPECT_FALSE, and EXPECT_TRUE.

168  {
169  for (int pass = 0; pass < 2; ++pass) {
170  reset(pass % 2 != 0);
171  reader_->setReadCB(&readCallback_);
172  writer_->write(getBuf("hello"), &writeCallback_);
173  writer_->closeOnEmpty();
174  writer_->write(getBuf("hello"), &writeCallback_);
175  eventBase_.loop();
176  EXPECT_EQ(readCallback_.getData(), "hello");
177  EXPECT_FALSE(readCallback_.error_);
178  EXPECT_EQ(writeCallback_.writes_, 1);
179  EXPECT_TRUE(writeCallback_.error_);
180  }
181 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862