removing non-existing file from the build
[folly.git] / folly / wangle / concurrent / test / CodelTest.cpp
1 /*
2  * Copyright 2015 Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <chrono>
18 #include <folly/wangle/concurrent/Codel.h>
19 #include <gtest/gtest.h>
20 #include <thread>
21
22 TEST(CodelTest, Basic) {
23   using std::chrono::milliseconds;
24   folly::wangle::Codel c;
25   std::this_thread::sleep_for(milliseconds(110));
26   // This interval is overloaded
27   EXPECT_FALSE(c.overloaded(milliseconds(100)));
28   std::this_thread::sleep_for(milliseconds(90));
29   // At least two requests must happen in an interval before they will fail
30   EXPECT_FALSE(c.overloaded(milliseconds(50)));
31   EXPECT_TRUE(c.overloaded(milliseconds(50)));
32   std::this_thread::sleep_for(milliseconds(110));
33   // Previous interval is overloaded, but 2ms isn't enough to fail
34   EXPECT_FALSE(c.overloaded(milliseconds(2)));
35   std::this_thread::sleep_for(milliseconds(90));
36   // 20 ms > target interval * 2
37   EXPECT_TRUE(c.overloaded(milliseconds(20)));
38 }