mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 02:42:27 +00:00
swarm/testutil: fix tests with seed
This commit is contained in:
parent
1df916baa5
commit
39d66957d3
2 changed files with 6 additions and 6 deletions
|
|
@ -44,11 +44,11 @@ import (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
commandName = ""
|
commandName = ""
|
||||||
seed int64 = time.Now().UTC().UnixNano()
|
seed = int(time.Now().UTC().UnixNano())
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rand.Seed(seed)
|
rand.Seed(int64(seed))
|
||||||
}
|
}
|
||||||
|
|
||||||
func httpEndpoint(host string) string {
|
func httpEndpoint(host string) string {
|
||||||
|
|
|
||||||
|
|
@ -47,9 +47,9 @@ func TempFileWithContent(t *testing.T, content string) string {
|
||||||
|
|
||||||
// RandomBytes returns pseudo-random deterministic result
|
// RandomBytes returns pseudo-random deterministic result
|
||||||
// because test fails must be reproducible
|
// because test fails must be reproducible
|
||||||
func RandomBytes(seed int64, length int) []byte {
|
func RandomBytes(seed, length int) []byte {
|
||||||
b := make([]byte, length)
|
b := make([]byte, length)
|
||||||
reader := rand.New(rand.NewSource(seed))
|
reader := rand.New(rand.NewSource(int64(seed)))
|
||||||
for n := 0; n < length; {
|
for n := 0; n < length; {
|
||||||
read, err := reader.Read(b[n:])
|
read, err := reader.Read(b[n:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -60,6 +60,6 @@ func RandomBytes(seed int64, length int) []byte {
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
func RandomReader(seed int64, length int) *bytes.Reader {
|
func RandomReader(seed, length int) *bytes.Reader {
|
||||||
return bytes.NewReader(RandomBytes(seed, length))
|
return bytes.NewReader(RandomBytes(seed, length))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue