forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrain_manager_impl_test.cc
78 lines (61 loc) · 2.25 KB
/
drain_manager_impl_test.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <chrono>
#include "server/drain_manager_impl.h"
#include "test/mocks/server/mocks.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
using testing::_;
using testing::InSequence;
using testing::Return;
using testing::SaveArg;
namespace Envoy {
namespace Server {
namespace {
class DrainManagerImplTest : public testing::Test {
public:
DrainManagerImplTest() {
ON_CALL(server_.options_, drainTime()).WillByDefault(Return(std::chrono::seconds(600)));
ON_CALL(server_.options_, parentShutdownTime())
.WillByDefault(Return(std::chrono::seconds(900)));
}
NiceMock<MockInstance> server_;
};
TEST_F(DrainManagerImplTest, Default) {
InSequence s;
DrainManagerImpl drain_manager(server_, envoy::api::v2::Listener_DrainType_DEFAULT);
// Test parent shutdown.
Event::MockTimer* shutdown_timer = new Event::MockTimer(&server_.dispatcher_);
EXPECT_CALL(*shutdown_timer, enableTimer(std::chrono::milliseconds(900000)));
drain_manager.startParentShutdownSequence();
EXPECT_CALL(server_.hot_restart_, sendParentTerminateRequest());
shutdown_timer->callback_();
// Verify basic drain close.
EXPECT_CALL(server_, healthCheckFailed()).WillOnce(Return(false));
EXPECT_FALSE(drain_manager.drainClose());
EXPECT_CALL(server_, healthCheckFailed()).WillOnce(Return(true));
EXPECT_TRUE(drain_manager.drainClose());
// Test drain sequence.
Event::MockTimer* drain_timer = new Event::MockTimer(&server_.dispatcher_);
EXPECT_CALL(*drain_timer, enableTimer(_));
ReadyWatcher drain_complete;
drain_manager.startDrainSequence([&drain_complete]() -> void { drain_complete.ready(); });
// 600s which is the default drain time.
for (size_t i = 0; i < 599; i++) {
if (i < 598) {
EXPECT_CALL(*drain_timer, enableTimer(_));
} else {
EXPECT_CALL(drain_complete, ready());
}
drain_timer->callback_();
}
EXPECT_CALL(server_, healthCheckFailed()).WillOnce(Return(false));
EXPECT_TRUE(drain_manager.drainClose());
}
TEST_F(DrainManagerImplTest, ModifyOnly) {
InSequence s;
DrainManagerImpl drain_manager(server_, envoy::api::v2::Listener_DrainType_MODIFY_ONLY);
EXPECT_CALL(server_, healthCheckFailed()).Times(0);
EXPECT_FALSE(drain_manager.drainClose());
}
} // namespace
} // namespace Server
} // namespace Envoy