@@ -19,6 +19,7 @@ import * as assert from 'assert';
19
19
import * as path from 'path' ;
20
20
import * as grpc from '../src' ;
21
21
import { loadProtoFile } from './common' ;
22
+ import { OutlierDetectionLoadBalancingConfig } from '../src/load-balancer-outlier-detection'
22
23
23
24
function multiDone ( done : Mocha . Done , target : number ) {
24
25
let count = 0 ;
@@ -67,6 +68,251 @@ const protoFile = path.join(__dirname, 'fixtures', 'echo_service.proto');
67
68
const EchoService = loadProtoFile ( protoFile )
68
69
. EchoService as grpc . ServiceClientConstructor ;
69
70
71
+ describe ( 'Outlier detection config validation' , ( ) => {
72
+ describe ( 'interval' , ( ) => {
73
+ it ( 'Should reject a negative interval' , ( ) => {
74
+ const loadBalancingConfig = {
75
+ interval : {
76
+ seconds : - 1 ,
77
+ nanos : 0
78
+ } ,
79
+ child_policy : [ { round_robin : { } } ]
80
+ } ;
81
+ assert . throws ( ( ) => {
82
+ OutlierDetectionLoadBalancingConfig . createFromJson ( loadBalancingConfig ) ;
83
+ } , / i n t e r v a l p a r s e e r r o r : v a l u e s o u t o f r a n g e f o r n o n - n e g a t i v e D u a r a t i o n / ) ;
84
+ } ) ;
85
+ it ( 'Should reject a large interval' , ( ) => {
86
+ const loadBalancingConfig = {
87
+ interval : {
88
+ seconds : 1e12 ,
89
+ nanos : 0
90
+ } ,
91
+ child_policy : [ { round_robin : { } } ]
92
+ } ;
93
+ assert . throws ( ( ) => {
94
+ OutlierDetectionLoadBalancingConfig . createFromJson ( loadBalancingConfig ) ;
95
+ } , / i n t e r v a l p a r s e e r r o r : v a l u e s o u t o f r a n g e f o r n o n - n e g a t i v e D u a r a t i o n / ) ;
96
+ } ) ;
97
+ it ( 'Should reject a negative interval.nanos' , ( ) => {
98
+ const loadBalancingConfig = {
99
+ interval : {
100
+ seconds : 0 ,
101
+ nanos : - 1
102
+ } ,
103
+ child_policy : [ { round_robin : { } } ]
104
+ } ;
105
+ assert . throws ( ( ) => {
106
+ OutlierDetectionLoadBalancingConfig . createFromJson ( loadBalancingConfig ) ;
107
+ } , / i n t e r v a l p a r s e e r r o r : v a l u e s o u t o f r a n g e f o r n o n - n e g a t i v e D u a r a t i o n / ) ;
108
+ } ) ;
109
+ it ( 'Should reject a large interval.nanos' , ( ) => {
110
+ const loadBalancingConfig = {
111
+ interval : {
112
+ seconds : 0 ,
113
+ nanos : 1e12
114
+ } ,
115
+ child_policy : [ { round_robin : { } } ]
116
+ } ;
117
+ assert . throws ( ( ) => {
118
+ OutlierDetectionLoadBalancingConfig . createFromJson ( loadBalancingConfig ) ;
119
+ } , / i n t e r v a l p a r s e e r r o r : v a l u e s o u t o f r a n g e f o r n o n - n e g a t i v e D u a r a t i o n / ) ;
120
+ } ) ;
121
+ } ) ;
122
+ describe ( 'base_ejection_time' , ( ) => {
123
+ it ( 'Should reject a negative base_ejection_time' , ( ) => {
124
+ const loadBalancingConfig = {
125
+ base_ejection_time : {
126
+ seconds : - 1 ,
127
+ nanos : 0
128
+ } ,
129
+ child_policy : [ { round_robin : { } } ]
130
+ } ;
131
+ assert . throws ( ( ) => {
132
+ OutlierDetectionLoadBalancingConfig . createFromJson ( loadBalancingConfig ) ;
133
+ } , / b a s e _ e j e c t i o n _ t i m e p a r s e e r r o r : v a l u e s o u t o f r a n g e f o r n o n - n e g a t i v e D u a r a t i o n / ) ;
134
+ } ) ;
135
+ it ( 'Should reject a large base_ejection_time' , ( ) => {
136
+ const loadBalancingConfig = {
137
+ base_ejection_time : {
138
+ seconds : 1e12 ,
139
+ nanos : 0
140
+ } ,
141
+ child_policy : [ { round_robin : { } } ]
142
+ } ;
143
+ assert . throws ( ( ) => {
144
+ OutlierDetectionLoadBalancingConfig . createFromJson ( loadBalancingConfig ) ;
145
+ } , / b a s e _ e j e c t i o n _ t i m e p a r s e e r r o r : v a l u e s o u t o f r a n g e f o r n o n - n e g a t i v e D u a r a t i o n / ) ;
146
+ } ) ;
147
+ it ( 'Should reject a negative base_ejection_time.nanos' , ( ) => {
148
+ const loadBalancingConfig = {
149
+ base_ejection_time : {
150
+ seconds : 0 ,
151
+ nanos : - 1
152
+ } ,
153
+ child_policy : [ { round_robin : { } } ]
154
+ } ;
155
+ assert . throws ( ( ) => {
156
+ OutlierDetectionLoadBalancingConfig . createFromJson ( loadBalancingConfig ) ;
157
+ } , / b a s e _ e j e c t i o n _ t i m e p a r s e e r r o r : v a l u e s o u t o f r a n g e f o r n o n - n e g a t i v e D u a r a t i o n / ) ;
158
+ } ) ;
159
+ it ( 'Should reject a large base_ejection_time.nanos' , ( ) => {
160
+ const loadBalancingConfig = {
161
+ base_ejection_time : {
162
+ seconds : 0 ,
163
+ nanos : 1e12
164
+ } ,
165
+ child_policy : [ { round_robin : { } } ]
166
+ } ;
167
+ assert . throws ( ( ) => {
168
+ OutlierDetectionLoadBalancingConfig . createFromJson ( loadBalancingConfig ) ;
169
+ } , / b a s e _ e j e c t i o n _ t i m e p a r s e e r r o r : v a l u e s o u t o f r a n g e f o r n o n - n e g a t i v e D u a r a t i o n / ) ;
170
+ } ) ;
171
+ } ) ;
172
+ describe ( 'max_ejection_time' , ( ) => {
173
+ it ( 'Should reject a negative max_ejection_time' , ( ) => {
174
+ const loadBalancingConfig = {
175
+ max_ejection_time : {
176
+ seconds : - 1 ,
177
+ nanos : 0
178
+ } ,
179
+ child_policy : [ { round_robin : { } } ]
180
+ } ;
181
+ assert . throws ( ( ) => {
182
+ OutlierDetectionLoadBalancingConfig . createFromJson ( loadBalancingConfig ) ;
183
+ } , / m a x _ e j e c t i o n _ t i m e p a r s e e r r o r : v a l u e s o u t o f r a n g e f o r n o n - n e g a t i v e D u a r a t i o n / ) ;
184
+ } ) ;
185
+ it ( 'Should reject a large max_ejection_time' , ( ) => {
186
+ const loadBalancingConfig = {
187
+ max_ejection_time : {
188
+ seconds : 1e12 ,
189
+ nanos : 0
190
+ } ,
191
+ child_policy : [ { round_robin : { } } ]
192
+ } ;
193
+ assert . throws ( ( ) => {
194
+ OutlierDetectionLoadBalancingConfig . createFromJson ( loadBalancingConfig ) ;
195
+ } , / m a x _ e j e c t i o n _ t i m e p a r s e e r r o r : v a l u e s o u t o f r a n g e f o r n o n - n e g a t i v e D u a r a t i o n / ) ;
196
+ } ) ;
197
+ it ( 'Should reject a negative max_ejection_time.nanos' , ( ) => {
198
+ const loadBalancingConfig = {
199
+ max_ejection_time : {
200
+ seconds : 0 ,
201
+ nanos : - 1
202
+ } ,
203
+ child_policy : [ { round_robin : { } } ]
204
+ } ;
205
+ assert . throws ( ( ) => {
206
+ OutlierDetectionLoadBalancingConfig . createFromJson ( loadBalancingConfig ) ;
207
+ } , / m a x _ e j e c t i o n _ t i m e p a r s e e r r o r : v a l u e s o u t o f r a n g e f o r n o n - n e g a t i v e D u a r a t i o n / ) ;
208
+ } ) ;
209
+ it ( 'Should reject a large max_ejection_time.nanos' , ( ) => {
210
+ const loadBalancingConfig = {
211
+ max_ejection_time : {
212
+ seconds : 0 ,
213
+ nanos : 1e12
214
+ } ,
215
+ child_policy : [ { round_robin : { } } ]
216
+ } ;
217
+ assert . throws ( ( ) => {
218
+ OutlierDetectionLoadBalancingConfig . createFromJson ( loadBalancingConfig ) ;
219
+ } , / m a x _ e j e c t i o n _ t i m e p a r s e e r r o r : v a l u e s o u t o f r a n g e f o r n o n - n e g a t i v e D u a r a t i o n / ) ;
220
+ } ) ;
221
+ } ) ;
222
+ describe ( 'max_ejection_percent' , ( ) => {
223
+ it ( 'Should reject a value above 100' , ( ) => {
224
+ const loadBalancingConfig = {
225
+ max_ejection_percent : 101 ,
226
+ child_policy : [ { round_robin : { } } ]
227
+ } ;
228
+ assert . throws ( ( ) => {
229
+ OutlierDetectionLoadBalancingConfig . createFromJson ( loadBalancingConfig ) ;
230
+ } , / m a x _ e j e c t i o n _ p e r c e n t p a r s e e r r o r : v a l u e o u t o f r a n g e f o r p e r c e n t a g e / ) ;
231
+ } ) ;
232
+ it ( 'Should reject a negative value' , ( ) => {
233
+ const loadBalancingConfig = {
234
+ max_ejection_percent : - 1 ,
235
+ child_policy : [ { round_robin : { } } ]
236
+ } ;
237
+ assert . throws ( ( ) => {
238
+ OutlierDetectionLoadBalancingConfig . createFromJson ( loadBalancingConfig ) ;
239
+ } , / m a x _ e j e c t i o n _ p e r c e n t p a r s e e r r o r : v a l u e o u t o f r a n g e f o r p e r c e n t a g e / ) ;
240
+ } ) ;
241
+ } ) ;
242
+ describe ( 'success_rate_ejection.enforcement_percentage' , ( ) => {
243
+ it ( 'Should reject a value above 100' , ( ) => {
244
+ const loadBalancingConfig = {
245
+ success_rate_ejection : {
246
+ enforcement_percentage : 101
247
+ } ,
248
+ child_policy : [ { round_robin : { } } ]
249
+ } ;
250
+ assert . throws ( ( ) => {
251
+ OutlierDetectionLoadBalancingConfig . createFromJson ( loadBalancingConfig ) ;
252
+ } , / s u c c e s s _ r a t e _ e j e c t i o n \. e n f o r c e m e n t _ p e r c e n t a g e p a r s e e r r o r : v a l u e o u t o f r a n g e f o r p e r c e n t a g e / ) ;
253
+ } ) ;
254
+ it ( 'Should reject a negative value' , ( ) => {
255
+ const loadBalancingConfig = {
256
+ success_rate_ejection : {
257
+ enforcement_percentage : - 1
258
+ } ,
259
+ child_policy : [ { round_robin : { } } ]
260
+ } ;
261
+ assert . throws ( ( ) => {
262
+ OutlierDetectionLoadBalancingConfig . createFromJson ( loadBalancingConfig ) ;
263
+ } , / s u c c e s s _ r a t e _ e j e c t i o n \. e n f o r c e m e n t _ p e r c e n t a g e p a r s e e r r o r : v a l u e o u t o f r a n g e f o r p e r c e n t a g e / ) ;
264
+ } ) ;
265
+ } ) ;
266
+ describe ( 'failure_percentage_ejection.threshold' , ( ) => {
267
+ it ( 'Should reject a value above 100' , ( ) => {
268
+ const loadBalancingConfig = {
269
+ failure_percentage_ejection : {
270
+ threshold : 101
271
+ } ,
272
+ child_policy : [ { round_robin : { } } ]
273
+ } ;
274
+ assert . throws ( ( ) => {
275
+ OutlierDetectionLoadBalancingConfig . createFromJson ( loadBalancingConfig ) ;
276
+ } , / f a i l u r e _ p e r c e n t a g e _ e j e c t i o n \. t h r e s h o l d p a r s e e r r o r : v a l u e o u t o f r a n g e f o r p e r c e n t a g e / ) ;
277
+ } ) ;
278
+ it ( 'Should reject a negative value' , ( ) => {
279
+ const loadBalancingConfig = {
280
+ failure_percentage_ejection : {
281
+ threshold : - 1
282
+ } ,
283
+ child_policy : [ { round_robin : { } } ]
284
+ } ;
285
+ assert . throws ( ( ) => {
286
+ OutlierDetectionLoadBalancingConfig . createFromJson ( loadBalancingConfig ) ;
287
+ } , / f a i l u r e _ p e r c e n t a g e _ e j e c t i o n \. t h r e s h o l d p a r s e e r r o r : v a l u e o u t o f r a n g e f o r p e r c e n t a g e / ) ;
288
+ } ) ;
289
+ } ) ;
290
+ describe ( 'failure_percentage_ejection.enforcement_percentage' , ( ) => {
291
+ it ( 'Should reject a value above 100' , ( ) => {
292
+ const loadBalancingConfig = {
293
+ failure_percentage_ejection : {
294
+ enforcement_percentage : 101
295
+ } ,
296
+ child_policy : [ { round_robin : { } } ]
297
+ } ;
298
+ assert . throws ( ( ) => {
299
+ OutlierDetectionLoadBalancingConfig . createFromJson ( loadBalancingConfig ) ;
300
+ } , / f a i l u r e _ p e r c e n t a g e _ e j e c t i o n \. e n f o r c e m e n t _ p e r c e n t a g e p a r s e e r r o r : v a l u e o u t o f r a n g e f o r p e r c e n t a g e / ) ;
301
+ } ) ;
302
+ it ( 'Should reject a negative value' , ( ) => {
303
+ const loadBalancingConfig = {
304
+ failure_percentage_ejection : {
305
+ enforcement_percentage : - 1
306
+ } ,
307
+ child_policy : [ { round_robin : { } } ]
308
+ } ;
309
+ assert . throws ( ( ) => {
310
+ OutlierDetectionLoadBalancingConfig . createFromJson ( loadBalancingConfig ) ;
311
+ } , / f a i l u r e _ p e r c e n t a g e _ e j e c t i o n \. e n f o r c e m e n t _ p e r c e n t a g e p a r s e e r r o r : v a l u e o u t o f r a n g e f o r p e r c e n t a g e / ) ;
312
+ } ) ;
313
+ } ) ;
314
+ } ) ;
315
+
70
316
describe ( 'Outlier detection' , ( ) => {
71
317
const GOOD_PORTS = 4 ;
72
318
let goodServer : grpc . Server ;
0 commit comments