Skip to content

Commit

Permalink
Updated the code for CI tests to work
Browse files Browse the repository at this point in the history
Updates #2346

Signed-off-by: Roman Zavodskikh <[email protected]>
  • Loading branch information
Roman Zavodskikh committed Aug 16, 2023
1 parent b03aaf2 commit 015b62f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
17 changes: 17 additions & 0 deletions loadbalancer/algorithm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()}})
Expand All @@ -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}}
Expand Down
5 changes: 5 additions & 0 deletions loadbalancer/fadein_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 015b62f

Please sign in to comment.