storage/driver: decrease memory allocation done during testsuite

Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
Stephen J Day 2015-12-07 18:54:22 -08:00
parent fb89fd30f8
commit be2985a35d

View file

@ -1135,12 +1135,19 @@ func randomFilename(length int64) string {
return string(b) return string(b)
} }
func randomContents(length int64) []byte { // randomBytes pre-allocates all of the memory sizes needed for the test. If
b := make([]byte, length) // anything panics while accessing randomBytes, just make this number bigger.
for i := range b { var randomBytes = make([]byte, 96<<20)
b[i] = byte(rand.Intn(2 << 8))
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 { type randReader struct {
@ -1151,14 +1158,14 @@ type randReader struct {
func (rr *randReader) Read(p []byte) (n int, err error) { func (rr *randReader) Read(p []byte) (n int, err error) {
rr.m.Lock() rr.m.Lock()
defer rr.m.Unlock() defer rr.m.Unlock()
for i := 0; i < len(p) && rr.r > 0; i++ {
p[i] = byte(rand.Intn(255)) n = copy(p, randomContents(int64(len(p))))
n++ rr.r -= int64(n)
rr.r--
} if rr.r <= 0 {
if rr.r == 0 {
err = io.EOF err = io.EOF
} }
return return
} }