forked from TrueCloudLab/distribution
storage/driver: decrease memory allocation done during testsuite
Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
parent
fb89fd30f8
commit
be2985a35d
1 changed files with 18 additions and 11 deletions
|
@ -1135,12 +1135,19 @@ func randomFilename(length int64) string {
|
|||
return string(b)
|
||||
}
|
||||
|
||||
func randomContents(length int64) []byte {
|
||||
b := make([]byte, length)
|
||||
for i := range b {
|
||||
b[i] = byte(rand.Intn(2 << 8))
|
||||
// randomBytes pre-allocates all of the memory sizes needed for the test. If
|
||||
// anything panics while accessing randomBytes, just make this number bigger.
|
||||
var randomBytes = make([]byte, 96<<20)
|
||||
|
||||
func init() {
|
||||
// increase the random bytes to the required maximum
|
||||
for i := range randomBytes {
|
||||
randomBytes[i] = byte(rand.Intn(2 << 8))
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
func randomContents(length int64) []byte {
|
||||
return randomBytes[:length]
|
||||
}
|
||||
|
||||
type randReader struct {
|
||||
|
@ -1151,14 +1158,14 @@ type randReader struct {
|
|||
func (rr *randReader) Read(p []byte) (n int, err error) {
|
||||
rr.m.Lock()
|
||||
defer rr.m.Unlock()
|
||||
for i := 0; i < len(p) && rr.r > 0; i++ {
|
||||
p[i] = byte(rand.Intn(255))
|
||||
n++
|
||||
rr.r--
|
||||
}
|
||||
if rr.r == 0 {
|
||||
|
||||
n = copy(p, randomContents(int64(len(p))))
|
||||
rr.r -= int64(n)
|
||||
|
||||
if rr.r <= 0 {
|
||||
err = io.EOF
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue