Skip to content

Commit c910b47

Browse files
stevvooeestesp
authored andcommitted
content/testsuite: ensure unique content per test
Signed-off-by: Stephen J Day <[email protected]>
1 parent 29a899b commit c910b47

1 file changed

Lines changed: 17 additions & 9 deletions

File tree

content/testsuite/testsuite.go

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"math/rand"
1010
"os"
1111
"runtime"
12+
"sync/atomic"
1213
"testing"
1314
"time"
1415

@@ -63,28 +64,28 @@ var labels = map[string]string{
6364
}
6465

6566
func checkContentStoreWriter(ctx context.Context, t *testing.T, cs content.Store) {
66-
c1, d1 := createContent(256, 1)
67+
c1, d1 := createContent(256)
6768
w1, err := cs.Writer(ctx, "c1", 0, "")
6869
if err != nil {
6970
t.Fatal(err)
7071
}
7172
defer w1.Close()
7273

73-
c2, d2 := createContent(256, 2)
74+
c2, d2 := createContent(256)
7475
w2, err := cs.Writer(ctx, "c2", int64(len(c2)), "")
7576
if err != nil {
7677
t.Fatal(err)
7778
}
7879
defer w2.Close()
7980

80-
c3, d3 := createContent(256, 3)
81+
c3, d3 := createContent(256)
8182
w3, err := cs.Writer(ctx, "c3", 0, d3)
8283
if err != nil {
8384
t.Fatal(err)
8485
}
8586
defer w3.Close()
8687

87-
c4, d4 := createContent(256, 4)
88+
c4, d4 := createContent(256)
8889
w4, err := cs.Writer(ctx, "c4", int64(len(c4)), d4)
8990
if err != nil {
9091
t.Fatal(err)
@@ -163,7 +164,7 @@ func checkResumeWriter(ctx context.Context, t *testing.T, cs content.Store) {
163164

164165
var (
165166
ref = "cb"
166-
cb, dgst = createContent(256, 10)
167+
cb, dgst = createContent(256)
167168
first, second = cb[:128], cb[128:]
168169
)
169170

@@ -223,7 +224,7 @@ func checkResumeWriter(ctx context.Context, t *testing.T, cs content.Store) {
223224
}
224225

225226
func checkUploadStatus(ctx context.Context, t *testing.T, cs content.Store) {
226-
c1, d1 := createContent(256, 17)
227+
c1, d1 := createContent(256)
227228

228229
preStart := time.Now()
229230
w1, err := cs.Writer(ctx, "c1", 256, d1)
@@ -292,7 +293,7 @@ func checkUploadStatus(ctx context.Context, t *testing.T, cs content.Store) {
292293
}
293294

294295
func checkLabels(ctx context.Context, t *testing.T, cs content.Store) {
295-
c1, d1 := createContent(256, 19)
296+
c1, d1 := createContent(256)
296297

297298
w1, err := cs.Writer(ctx, "c1", 256, d1)
298299
if err != nil {
@@ -365,7 +366,7 @@ func checkResume(rf func(context.Context, content.Writer, []byte, int64, int64,
365366

366367
for i, size := range sizes {
367368
for j, tp := range truncations {
368-
b, d := createContent(size, int64(i*len(truncations)+j))
369+
b, d := createContent(size)
369370
limit := int64(float64(size) * tp)
370371
ref := fmt.Sprintf("ref-%d-%d", i, j)
371372

@@ -548,7 +549,14 @@ func checkInfo(ctx context.Context, cs content.Store, d digest.Digest, expected
548549
return nil
549550
}
550551

551-
func createContent(size, seed int64) ([]byte, digest.Digest) {
552+
var contentSeed int64
553+
554+
func createContent(size int64) ([]byte, digest.Digest) {
555+
// each time we call this, we want to get a different seed, but it should
556+
// be related to the intitialization order and fairly consistent between
557+
// test runs. An atomic integer works just good enough for this.
558+
seed := atomic.AddInt64(&contentSeed, 1)
559+
552560
b, err := ioutil.ReadAll(io.LimitReader(rand.New(rand.NewSource(seed)), size))
553561
if err != nil {
554562
panic(err)

0 commit comments

Comments
 (0)