Skip to content

Commit

Permalink
Improve fadeIn CI tests
Browse files Browse the repository at this point in the history
+ added tests for powerOfNRandomChoices monotony
+ added tests for case when all endpoints are new
+ added tests (obviously failing at the moment) for powerOfNRandomChoices
to check new and old enpoints receive correct amount of requests

Signed-off-by: Roman Zavodskikh <[email protected]>
  • Loading branch information
Roman Zavodskikh committed Jan 12, 2024
1 parent d238294 commit 49e47e8
Showing 1 changed file with 39 additions and 9 deletions.
48 changes: 39 additions & 9 deletions loadbalancer/fadein_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,21 @@ func newConsistentHashForTest(endpoints []string) routing.LBAlgorithm {
return newConsistentHashInternal(endpoints, 1000)
}

// Those tests check that the amount of requests per period for each endpoint is monotonical over the time.
// For every endpoint, it could increase, decrease or stay the same.
func TestFadeIn(t *testing.T) {
old := 2 * fadeInDuration
testFadeIn(t, "power-of-n-random-choices, 0", newPowerOfRandomNChoices, old, old)
testFadeIn(t, "power-of-n-random-choices, 1", newPowerOfRandomNChoices, 0, old)
testFadeIn(t, "power-of-n-random-choices, 2", newPowerOfRandomNChoices, 0, 0)
testFadeIn(t, "power-of-n-random-choices, 3", newPowerOfRandomNChoices, old, 0)
testFadeIn(t, "power-of-n-random-choices, 4", newPowerOfRandomNChoices, old, old, old, 0)
testFadeIn(t, "power-of-n-random-choices, 5", newPowerOfRandomNChoices, old, old, old, 0, 0, 0)
testFadeIn(t, "power-of-n-random-choices, 6", newPowerOfRandomNChoices, old, 0, 0, 0)
testFadeIn(t, "power-of-n-random-choices, 7", newPowerOfRandomNChoices, old, 0, 0, 0, 0, 0, 0)
testFadeIn(t, "power-of-n-random-choices, 8", newPowerOfRandomNChoices, 0, 0, 0, 0, 0, 0)
testFadeIn(t, "power-of-n-random-choices, 9", newPowerOfRandomNChoices, fadeInDuration/2, fadeInDuration/3, fadeInDuration/4)

testFadeIn(t, "round-robin, 0", newRoundRobin, old, old)
testFadeIn(t, "round-robin, 1", newRoundRobin, 0, old)
testFadeIn(t, "round-robin, 2", newRoundRobin, 0, 0)
Expand Down Expand Up @@ -205,7 +218,7 @@ func TestFadeIn(t *testing.T) {
testFadeIn(t, "consistent-hash, 9", newConsistentHashForTest, fadeInDuration/2, fadeInDuration/3, fadeInDuration/4)
}

func testFadeInLoadBetweenOldEps(
func testFadeInLoadBetweenOldAndNewEps(
t *testing.T,
name string,
algorithm func([]string) routing.LBAlgorithm,
Expand Down Expand Up @@ -241,21 +254,38 @@ func testFadeInLoadBetweenOldEps(
nReqs[ep.Host]++
}

expectedReqsPerOldEndpoint := numberOfReqs / nOld
for idx, ep := range eps {
if endpointAges[idx] == old {
assert.InEpsilon(t, expectedReqsPerOldEndpoint, nReqs[ep], 0.2)
if nOld == 0 {
expectedReqsPerEndpoint := numberOfReqs / nNew
for _, ep := range eps {
assert.InEpsilon(t, expectedReqsPerEndpoint, nReqs[ep], 0.2)
}
if endpointAges[idx] == new {
assert.InDelta(t, 0, nReqs[ep], acceptableErrorNearZero)
} else {
expectedReqsPerOldEndpoint := numberOfReqs / nOld
for idx, ep := range eps {
if endpointAges[idx] == old {
assert.InEpsilon(t, expectedReqsPerOldEndpoint, nReqs[ep], 0.2)
}
if endpointAges[idx] == new {
assert.InDelta(t, 0, nReqs[ep], acceptableErrorNearZero)
}
}
}
})
}

func TestFadeInLoadBetweenOldEps(t *testing.T) {
for nOld := 1; nOld < 6; nOld++ {
// Those tests check that the amount of requests per period for every endpoint at the very beginning of fading in (when all endpoints are new)
// and at the very end of fading in (when all endpoints are old) is correct.
func TestFadeInLoadBetweenOldAndNewEps(t *testing.T) {
for nOld := 0; nOld < 6; nOld++ {
for nNew := 0; nNew < 6; nNew++ {
if nOld == 0 && nNew == 0 {
continue
}

// This test does not work with power of n random choices at the moment, because there is no fadein for
// this algorithm. Feel free to uncomment this line when this problem is fixed.
// testFadeInLoadBetweenOldEps(t, fmt.Sprintf("power-of-n-random-choices, %d old, %d new", nOld, nNew), newPowerOfRandomNChoices, nOld, nNew)

testFadeInLoadBetweenOldEps(t, fmt.Sprintf("consistent-hash, %d old, %d new", nOld, nNew), newConsistentHash, nOld, nNew)

Check failure on line 289 in loadbalancer/fadein_test.go

View workflow job for this annotation

GitHub Actions / tests

undefined: testFadeInLoadBetweenOldEps

Check failure on line 289 in loadbalancer/fadein_test.go

View workflow job for this annotation

GitHub Actions / check-race

undefined: testFadeInLoadBetweenOldEps
testFadeInLoadBetweenOldEps(t, fmt.Sprintf("random, %d old, %d new", nOld, nNew), newRandom, nOld, nNew)

Check failure on line 290 in loadbalancer/fadein_test.go

View workflow job for this annotation

GitHub Actions / tests

undefined: testFadeInLoadBetweenOldEps

Check failure on line 290 in loadbalancer/fadein_test.go

View workflow job for this annotation

GitHub Actions / check-race

undefined: testFadeInLoadBetweenOldEps
testFadeInLoadBetweenOldEps(t, fmt.Sprintf("round-robin, %d old, %d new", nOld, nNew), newRoundRobin, nOld, nNew)

Check failure on line 291 in loadbalancer/fadein_test.go

View workflow job for this annotation

GitHub Actions / tests

undefined: testFadeInLoadBetweenOldEps

Check failure on line 291 in loadbalancer/fadein_test.go

View workflow job for this annotation

GitHub Actions / check-race

undefined: testFadeInLoadBetweenOldEps
Expand Down

0 comments on commit 49e47e8

Please sign in to comment.