proxygen
CodelTest.cpp File Reference
#include <folly/executors/Codel.h>
#include <folly/portability/GTest.h>
#include <chrono>
#include <thread>

Go to the source code of this file.

Functions

 TEST (CodelTest, Basic)
 
 TEST (CodelTest, highLoad)
 
 TEST (CodelTest, mediumLoad)
 
 TEST (CodelTest, reducingLoad)
 
 TEST (CodelTest, oneRequestNoDrop)
 
 TEST (CodelTest, getLoadSanity)
 

Function Documentation

TEST ( CodelTest  ,
Basic   
)

Definition at line 25 of file CodelTest.cpp.

References c, EXPECT_FALSE, EXPECT_TRUE, and folly::Codel::overloaded().

25  {
27  std::this_thread::sleep_for(milliseconds(110));
28  // This interval is overloaded
29  EXPECT_FALSE(c.overloaded(milliseconds(100)));
30  std::this_thread::sleep_for(milliseconds(90));
31  // At least two requests must happen in an interval before they will fail
32  EXPECT_FALSE(c.overloaded(milliseconds(50)));
33  EXPECT_TRUE(c.overloaded(milliseconds(50)));
34  std::this_thread::sleep_for(milliseconds(110));
35  // Previous interval is overloaded, but 2ms isn't enough to fail
36  EXPECT_FALSE(c.overloaded(milliseconds(2)));
37  std::this_thread::sleep_for(milliseconds(90));
38  // 20 ms > target interval * 2
39  EXPECT_TRUE(c.overloaded(milliseconds(20)));
40 }
bool overloaded(std::chrono::nanoseconds delay)
Definition: Codel.cpp:37
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
char c
TEST ( CodelTest  ,
highLoad   
)

Definition at line 42 of file CodelTest.cpp.

References c, EXPECT_EQ, folly::Codel::getLoad(), and folly::Codel::overloaded().

42  {
44  c.overloaded(milliseconds(40));
45  EXPECT_EQ(100, c.getLoad());
46 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
int getLoad()
Definition: Codel.cpp:83
bool overloaded(std::chrono::nanoseconds delay)
Definition: Codel.cpp:37
char c
TEST ( CodelTest  ,
mediumLoad   
)

Definition at line 48 of file CodelTest.cpp.

References c, EXPECT_FALSE, EXPECT_GT, folly::Codel::getLoad(), and folly::Codel::overloaded().

48  {
50  c.overloaded(milliseconds(20));
51  sleep_for(milliseconds(90));
52  // this is overloaded but this request shouldn't drop because it's not >
53  // slough timeout
54  EXPECT_FALSE(c.overloaded(milliseconds(8)));
55  EXPECT_GT(100, c.getLoad());
56 }
int getLoad()
Definition: Codel.cpp:83
bool overloaded(std::chrono::nanoseconds delay)
Definition: Codel.cpp:37
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
char c
#define EXPECT_GT(val1, val2)
Definition: gtest.h:1934
TEST ( CodelTest  ,
reducingLoad   
)

Definition at line 58 of file CodelTest.cpp.

References c, EXPECT_FALSE, and folly::Codel::overloaded().

58  {
60  c.overloaded(milliseconds(20));
61  sleep_for(milliseconds(90));
62  EXPECT_FALSE(c.overloaded(milliseconds(4)));
63 }
bool overloaded(std::chrono::nanoseconds delay)
Definition: Codel.cpp:37
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
char c
TEST ( CodelTest  ,
oneRequestNoDrop   
)

Definition at line 65 of file CodelTest.cpp.

References c, EXPECT_FALSE, and folly::Codel::overloaded().

65  {
67  EXPECT_FALSE(c.overloaded(milliseconds(20)));
68 }
bool overloaded(std::chrono::nanoseconds delay)
Definition: Codel.cpp:37
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
char c
TEST ( CodelTest  ,
getLoadSanity   
)

Definition at line 70 of file CodelTest.cpp.

References c, EXPECT_GT, EXPECT_LT, folly::Codel::getLoad(), and folly::Codel::overloaded().

70  {
72  // should be 100% but leave a litte wiggle room.
73  c.overloaded(milliseconds(10));
74  EXPECT_LT(99, c.getLoad());
75  EXPECT_GT(101, c.getLoad());
76 
77  // should be 70% but leave a litte wiggle room.
78  c.overloaded(milliseconds(7));
79  EXPECT_LT(60, c.getLoad());
80  EXPECT_GT(80, c.getLoad());
81 
82  // should be 20% but leave a litte wiggle room.
83  c.overloaded(milliseconds(2));
84  EXPECT_LT(10, c.getLoad());
85  EXPECT_GT(30, c.getLoad());
86 
87  // this test demonstrates how silly getLoad() is, but silly isn't
88  // necessarily useless
89 }
int getLoad()
Definition: Codel.cpp:83
bool overloaded(std::chrono::nanoseconds delay)
Definition: Codel.cpp:37
#define EXPECT_LT(val1, val2)
Definition: gtest.h:1930
char c
#define EXPECT_GT(val1, val2)
Definition: gtest.h:1934