Skip to content

Commit b8da460

Browse files
authored
Merge pull request #2223 from murgatroid99/grpc-js_outlier_detection_validation_tests
grpc-js: Add tests for outlier detection validation rules
2 parents 9dd9cb0 + f438191 commit b8da460

File tree

1 file changed

+246
-0
lines changed

1 file changed

+246
-0
lines changed

packages/grpc-js/test/test-outlier-detection.ts

Lines changed: 246 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import * as assert from 'assert';
1919
import * as path from 'path';
2020
import * as grpc from '../src';
2121
import { loadProtoFile } from './common';
22+
import { OutlierDetectionLoadBalancingConfig } from '../src/load-balancer-outlier-detection'
2223

2324
function multiDone(done: Mocha.Done, target: number) {
2425
let count = 0;
@@ -67,6 +68,251 @@ const protoFile = path.join(__dirname, 'fixtures', 'echo_service.proto');
6768
const EchoService = loadProtoFile(protoFile)
6869
.EchoService as grpc.ServiceClientConstructor;
6970

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+
}, /interval parse error: values out of range for non-negative Duaration/);
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+
}, /interval parse error: values out of range for non-negative Duaration/);
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+
}, /interval parse error: values out of range for non-negative Duaration/);
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+
}, /interval parse error: values out of range for non-negative Duaration/);
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+
}, /base_ejection_time parse error: values out of range for non-negative Duaration/);
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+
}, /base_ejection_time parse error: values out of range for non-negative Duaration/);
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+
}, /base_ejection_time parse error: values out of range for non-negative Duaration/);
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+
}, /base_ejection_time parse error: values out of range for non-negative Duaration/);
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+
}, /max_ejection_time parse error: values out of range for non-negative Duaration/);
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+
}, /max_ejection_time parse error: values out of range for non-negative Duaration/);
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+
}, /max_ejection_time parse error: values out of range for non-negative Duaration/);
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+
}, /max_ejection_time parse error: values out of range for non-negative Duaration/);
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+
}, /max_ejection_percent parse error: value out of range for percentage/);
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+
}, /max_ejection_percent parse error: value out of range for percentage/);
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+
}, /success_rate_ejection\.enforcement_percentage parse error: value out of range for percentage/);
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+
}, /success_rate_ejection\.enforcement_percentage parse error: value out of range for percentage/);
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+
}, /failure_percentage_ejection\.threshold parse error: value out of range for percentage/);
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+
}, /failure_percentage_ejection\.threshold parse error: value out of range for percentage/);
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+
}, /failure_percentage_ejection\.enforcement_percentage parse error: value out of range for percentage/);
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+
}, /failure_percentage_ejection\.enforcement_percentage parse error: value out of range for percentage/);
312+
});
313+
});
314+
});
315+
70316
describe('Outlier detection', () => {
71317
const GOOD_PORTS = 4;
72318
let goodServer: grpc.Server;

0 commit comments

Comments
 (0)