Skip to content

Commit

Permalink
chore: rm useless and unstable tests codes (#223)
Browse files Browse the repository at this point in the history
* chore: rm linked fast rand for test

* chore: rm unstable ci assert

* chore: spped up TestDigest
  • Loading branch information
joway authored Aug 5, 2024
1 parent 4d9cac1 commit 4f14cd9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 21 deletions.
13 changes: 7 additions & 6 deletions cloud/circuitbreaker/metricer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,13 @@ func TestMetricser1(t *testing.T) {

rate := m.ErrorRate()
assert(t, rate > .6 && rate < .7)
s = m.Successes()
assert(t, s > int64(tot/3-1000) && s < int64(tot/3+1000))
f = m.Failures()
assert(t, f > int64(tot/3-1000) && f < int64(tot/3+1000))
ts := m.Timeouts()
assert(t, ts > int64(tot/3-1000) && ts < int64(tot/3+1000))
// it's not guaranteed in unstable ci env
//s = m.Successes()
//assert(t, s > int64(tot/3-1000) && s < int64(tot/3+1000))
//f = m.Failures()
//assert(t, f > int64(tot/3-1000) && f < int64(tot/3+1000))
//ts := m.Timeouts()
//assert(t, ts > int64(tot/3-1000) && ts < int64(tot/3+1000))
}

// TestMetricser2 tests functions about time
Expand Down
21 changes: 6 additions & 15 deletions internal/wyhash/digest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,26 @@ package wyhash

import (
"fmt"
"math/rand"
"runtime"
"testing"

_ "unsafe" // for linkname
)

//go:linkname runtime_fastrand runtime.fastrand
func runtime_fastrand() uint32

//go:nosplit
func fastrandn(n uint32) uint32 {
// This is similar to Uint32() % n, but faster.
// See https://lemire.me/blog/2016/06/27/a-fast-alternative-to-the-modulo-reduction/
return uint32(uint64(runtime_fastrand()) * uint64(n) >> 32)
}

func TestDigest(t *testing.T) {
d := NewDefault()
for size := 0; size <= 1024; size++ {
data := make([]byte, size)
for i := range data {
data[i] = byte(fastrandn(256))
data[i] = byte(rand.Int31n(256))
}
// Random write small data.
var r int
if size == 0 {
r = 0
} else {
r = int(fastrandn(uint32(len(data))))
r = int(rand.Int31n(int32(len(data))))
}
d.Write(data[:r])
d.Write(data[r:])
Expand All @@ -54,9 +45,9 @@ func TestDigest(t *testing.T) {
d.Reset()
}

largedata := make([]byte, 1024*1024)
largedata := make([]byte, 10*1024)
for i := range largedata {
largedata[i] = byte(fastrandn(256))
largedata[i] = byte(rand.Int31n(256))
}

var a, b int
Expand All @@ -66,7 +57,7 @@ func TestDigest(t *testing.T) {
if len(largedata)-a < 300 {
b = len(largedata) - a
} else {
b = int(fastrandn(uint32(partsizelimit)))
b = int(rand.Int31n(int32(partsizelimit)))
}
digest.Write(largedata[a : a+b])
if Sum64(largedata[:a+b]) != digest.Sum64() {
Expand Down

0 comments on commit 4f14cd9

Please sign in to comment.