From 015b62f4c8ec90806efc561cdab9d2b6da64ffe4 Mon Sep 17 00:00:00 2001 From: Roman Zavodskikh Date: Thu, 1 Jun 2023 14:16:34 +0200 Subject: [PATCH] Updated the code for CI tests to work Updates #2346 Signed-off-by: Roman Zavodskikh --- loadbalancer/algorithm_test.go | 17 +++++++++++++++++ loadbalancer/fadein_test.go | 5 +++++ 2 files changed, 22 insertions(+) diff --git a/loadbalancer/algorithm_test.go b/loadbalancer/algorithm_test.go index ac7dc365b7..c838e5d128 100644 --- a/loadbalancer/algorithm_test.go +++ b/loadbalancer/algorithm_test.go @@ -300,6 +300,11 @@ func TestConsistentHashBoundedLoadSearch(t *testing.T) { LBAlgorithm: ConsistentHash.String(), LBEndpoints: endpoints, })})[0] + route.HealthyEndpointsSet = map[routing.LBEndpoint]struct{}{} + for _, ep := range route.LBEndpoints { + route.HealthyEndpointsSet[ep] = struct{}{} + } + route.HealthyEndpoints = route.LBEndpoints ch := route.LBAlgorithm.(*consistentHash) ctx := &routing.LBContext{Request: r, Route: route, Params: map[string]interface{}{ConsistentHashBalanceFactor: 1.25}} noLoad := ch.Apply(ctx) @@ -344,6 +349,11 @@ func TestConsistentHashKey(t *testing.T) { LBEndpoints: endpoints, }), })[0] + rt.HealthyEndpointsSet = map[routing.LBEndpoint]struct{}{} + for _, ep := range rt.LBEndpoints { + rt.HealthyEndpointsSet[ep] = struct{}{} + } + rt.HealthyEndpoints = rt.LBEndpoints defaultEndpoint := ch.Apply(&routing.LBContext{Request: r, Route: rt, Params: make(map[string]interface{})}) remoteHostEndpoint := ch.Apply(&routing.LBContext{Request: r, Route: rt, Params: map[string]interface{}{ConsistentHashKey: net.RemoteHost(r).String()}}) @@ -364,11 +374,18 @@ func TestConsistentHashKey(t *testing.T) { func TestConsistentHashBoundedLoadDistribution(t *testing.T) { endpoints := []string{"http://127.0.0.1:8080", "http://127.0.0.2:8080", "http://127.0.0.3:8080"} r, _ := http.NewRequest("GET", "http://127.0.0.1:1234/foo", nil) + route := NewAlgorithmProvider().Do([]*routing.Route{routing.NewRoute(eskip.Route{ BackendType: eskip.LBBackend, LBAlgorithm: ConsistentHash.String(), LBEndpoints: endpoints, })})[0] + route.HealthyEndpoints = route.LBEndpoints + route.HealthyEndpointsSet = map[routing.LBEndpoint]struct{}{} + for _, ep := range route.LBEndpoints { + route.HealthyEndpointsSet[ep] = struct{}{} + } + ch := route.LBAlgorithm.(*consistentHash) balanceFactor := 1.25 ctx := &routing.LBContext{Request: r, Route: route, Params: map[string]interface{}{ConsistentHashBalanceFactor: balanceFactor}} diff --git a/loadbalancer/fadein_test.go b/loadbalancer/fadein_test.go index c68acefe24..6a81ef0cc7 100644 --- a/loadbalancer/fadein_test.go +++ b/loadbalancer/fadein_test.go @@ -328,6 +328,11 @@ func benchmarkFadeIn( Detected: detectionTimes[i], }) } + route.HealthyEndpoints = route.LBEndpoints + route.HealthyEndpointsSet = make(map[routing.LBEndpoint]struct{}) + for i := range route.LBEndpoints { + route.HealthyEndpointsSet[route.LBEndpoints[i]] = struct{}{} + } var wg sync.WaitGroup