Skip to content

Commit

Permalink
fix: The random sample size is too small, which can easily cause unit…
Browse files Browse the repository at this point in the history
… tests to fail.

* lint: should omit type int from declaration of var randomNumber

* lint: gofumpt
  • Loading branch information
harbourlga committed Nov 5, 2024
1 parent 3ecb1d6 commit 231cc8b
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions selector/random/random_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ func TestWrr(t *testing.T) {
}))
random.Apply(nodes)
var count1, count2 int
for i := 0; i < 200; i++ {
randomNumber := 2000
for i := 0; i < randomNumber; i++ {
n, done, err := random.Select(context.Background(), selector.WithNodeFilter(filter.Version("v2.0.0")))
if err != nil {
t.Errorf("expect no error, got %v", err)
Expand All @@ -48,17 +49,20 @@ func TestWrr(t *testing.T) {
count2++
}
}
if count1 <= 80 {
t.Errorf("count1(%v) <= 80", count1)
// output
percentage1 := float64(count1) / float64(randomNumber) * 100
percentage2 := float64(count2) / float64(randomNumber) * 100
if percentage1 > 60 {
t.Errorf("percentage1(%v) > 60", percentage1)
}
if count1 >= 120 {
t.Errorf("count1(%v) >= 120", count1)
if percentage1 < 40 {
t.Errorf("percentage1(%v) < 40", percentage1)
}
if count2 <= 80 {
t.Errorf("count2(%v) <= 80", count2)
if percentage2 > 60 {
t.Errorf("percentage2(%v) > 60", percentage2)
}
if count2 >= 120 {
t.Errorf("count2(%v) >= 120", count2)
if percentage2 < 40 {
t.Errorf("percentage2(%v) < 40", percentage2)
}
}

Expand Down

0 comments on commit 231cc8b

Please sign in to comment.