forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrpc_subscription_impl_test.cc
113 lines (97 loc) · 4.61 KB
/
grpc_subscription_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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "test/common/config/grpc_subscription_test_harness.h"
#include "gtest/gtest.h"
using testing::InSequence;
namespace Envoy {
namespace Config {
namespace {
class GrpcSubscriptionImplTest : public testing::TestWithParam<LegacyOrUnified>,
public GrpcSubscriptionTestHarness {
public:
GrpcSubscriptionImplTest() : GrpcSubscriptionTestHarness(GetParam()) {}
};
INSTANTIATE_TEST_SUITE_P(GrpcSubscriptionImplTest, GrpcSubscriptionImplTest,
testing::ValuesIn({LegacyOrUnified::Legacy, LegacyOrUnified::Unified}));
// Validate that stream creation results in a timer based retry and can recover.
TEST_P(GrpcSubscriptionImplTest, StreamCreationFailure) {
InSequence s;
EXPECT_CALL(*async_client_, startRaw(_, _, _, _)).WillOnce(Return(nullptr));
// onConfigUpdateFailed() should not be called for gRPC stream connection failure
EXPECT_CALL(callbacks_,
onConfigUpdateFailed(Envoy::Config::ConfigUpdateFailureReason::ConnectionFailure, _))
.Times(0);
EXPECT_CALL(random_, random());
EXPECT_CALL(*timer_, enableTimer(_, _));
subscription_->start({"cluster0", "cluster1"});
EXPECT_TRUE(statsAre(2, 0, 0, 1, 0, 0, 0, ""));
// Ensure this doesn't cause an issue by sending a request, since we don't
// have a gRPC stream.
subscription_->updateResourceInterest({"cluster2"});
// Retry and succeed.
EXPECT_CALL(*async_client_, startRaw(_, _, _, _)).WillOnce(Return(&async_stream_));
expectSendMessage({"cluster2"}, "", true);
timer_->invokeCallback();
EXPECT_TRUE(statsAre(3, 0, 0, 1, 0, 0, 0, ""));
verifyControlPlaneStats(1);
}
// Validate that the client can recover from a remote stream closure via retry.
TEST_P(GrpcSubscriptionImplTest, RemoteStreamClose) {
startSubscription({"cluster0", "cluster1"});
EXPECT_TRUE(statsAre(1, 0, 0, 0, 0, 0, 0, ""));
// onConfigUpdateFailed() should not be called for gRPC stream connection failure
EXPECT_CALL(callbacks_,
onConfigUpdateFailed(Envoy::Config::ConfigUpdateFailureReason::ConnectionFailure, _))
.Times(0);
EXPECT_CALL(*timer_, enableTimer(_, _));
EXPECT_CALL(random_, random());
onRemoteClose();
EXPECT_TRUE(statsAre(2, 0, 0, 1, 0, 0, 0, ""));
verifyControlPlaneStats(0);
// Retry and succeed.
EXPECT_CALL(*async_client_, startRaw(_, _, _, _)).WillOnce(Return(&async_stream_));
expectSendMessage({"cluster0", "cluster1"}, "", true);
timer_->invokeCallback();
EXPECT_TRUE(statsAre(2, 0, 0, 1, 0, 0, 0, ""));
}
// Validate that When the management server gets multiple requests for the same version, it can
// ignore later ones. This allows the nonce to be used.
TEST_P(GrpcSubscriptionImplTest, RepeatedNonce) {
InSequence s;
startSubscription({"cluster0", "cluster1"});
EXPECT_TRUE(statsAre(1, 0, 0, 0, 0, 0, 0, ""));
// First with the initial, empty version update to "0".
updateResourceInterest({"cluster2"});
EXPECT_TRUE(statsAre(2, 0, 0, 0, 0, 0, 0, ""));
deliverConfigUpdate({"cluster0", "cluster2"}, "0", false);
EXPECT_TRUE(statsAre(3, 0, 1, 0, 0, 0, 0, ""));
deliverConfigUpdate({"cluster0", "cluster2"}, "0", true);
EXPECT_TRUE(statsAre(4, 1, 1, 0, 0, TEST_TIME_MILLIS, 7148434200721666028, "0"));
// Now with version "0" update to "1".
updateResourceInterest({"cluster3"});
EXPECT_TRUE(statsAre(5, 1, 1, 0, 0, TEST_TIME_MILLIS, 7148434200721666028, "0"));
deliverConfigUpdate({"cluster3"}, "42", false);
EXPECT_TRUE(statsAre(6, 1, 2, 0, 0, TEST_TIME_MILLIS, 7148434200721666028, "0"));
deliverConfigUpdate({"cluster3"}, "42", true);
EXPECT_TRUE(statsAre(7, 2, 2, 0, 0, TEST_TIME_MILLIS, 7919287270473417401, "42"));
}
TEST_P(GrpcSubscriptionImplTest, UpdateTimeNotChangedOnUpdateReject) {
InSequence s;
startSubscription({"cluster0", "cluster1"});
EXPECT_TRUE(statsAre(1, 0, 0, 0, 0, 0, 0, ""));
deliverConfigUpdate({"cluster0", "cluster2"}, "0", false);
EXPECT_TRUE(statsAre(2, 0, 1, 0, 0, 0, 0, ""));
}
TEST_P(GrpcSubscriptionImplTest, UpdateTimeChangedOnUpdateSuccess) {
InSequence s;
startSubscription({"cluster0", "cluster1"});
EXPECT_TRUE(statsAre(1, 0, 0, 0, 0, 0, 0, ""));
deliverConfigUpdate({"cluster0", "cluster2"}, "0", true);
EXPECT_TRUE(statsAre(2, 1, 0, 0, 0, TEST_TIME_MILLIS, 7148434200721666028, "0"));
// Advance the simulated time and verify that a trivial update (no change) also changes the update
// time.
simTime().setSystemTime(SystemTime(std::chrono::milliseconds(TEST_TIME_MILLIS + 1)));
deliverConfigUpdate({"cluster0", "cluster2"}, "0", true);
EXPECT_TRUE(statsAre(2, 2, 0, 0, 0, TEST_TIME_MILLIS + 1, 7148434200721666028, "0"));
}
} // namespace
} // namespace Config
} // namespace Envoy