MCPcopy Create free account
hub / github.com/zalando/skipper / TestApply

Function TestApply

loadbalancer/algorithm_test.go:228–296  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

226}
227
228func TestApply(t *testing.T) {
229 const R = 1000
230 const N = 10
231 eps := make([]string, 0, N)
232 for i := 0; i < N; i++ {
233 ep := fmt.Sprintf("http://127.0.0.1:123%d/foo", i)
234 eps = append(eps, ep)
235 }
236
237 for _, tt := range []struct {
238 name string
239 expected int
240 algorithm routing.LBAlgorithm
241 algorithmName string
242 }{
243 {
244 name: "random algorithm",
245 expected: N,
246 algorithm: newRandom(eps),
247 algorithmName: "random",
248 }, {
249 name: "roundrobin algorithm",
250 expected: N,
251 algorithm: newRoundRobin(eps),
252 algorithmName: "roundRobin",
253 }, {
254 name: "consistentHash algorithm",
255 expected: 1,
256 algorithm: newConsistentHash(eps),
257 algorithmName: "consistentHash",
258 }, {
259 name: "powerOfRandomNChoices algorithm",
260 expected: N,
261 algorithm: newPowerOfRandomNChoices(eps),
262 algorithmName: "powerOfRandomNChoices",
263 }} {
264 t.Run(tt.name, func(t *testing.T) {
265 req, _ := http.NewRequest("GET", "http://127.0.0.1:1234/foo", nil)
266 p := NewAlgorithmProvider()
267 endpointRegistry := routing.NewEndpointRegistry(routing.RegistryOptions{})
268 defer endpointRegistry.Close()
269 r := &routing.Route{
270 Route: eskip.Route{
271 BackendType: eskip.LBBackend,
272 LBAlgorithm: tt.algorithmName,
273 LBEndpoints: eskip.NewLBEndpoints(eps),
274 },
275 }
276 rt := p.Do([]*routing.Route{r})
277 endpointRegistry.Do([]*routing.Route{r})
278
279 lbctx := &routing.LBContext{
280 Request: req,
281 Route: rt[0],
282 LBEndpoints: rt[0].LBEndpoints,
283 }
284
285 h := make(map[string]int)

Callers

nothing calls this directly

Calls 11

CloseMethod · 0.95
DoMethod · 0.95
NewEndpointRegistryFunction · 0.92
NewLBEndpointsFunction · 0.92
newRandomFunction · 0.85
newRoundRobinFunction · 0.85
newConsistentHashFunction · 0.85
newPowerOfRandomNChoicesFunction · 0.85
NewAlgorithmProviderFunction · 0.85
DoMethod · 0.65
ApplyMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…