|
9 | 9 | "math/rand" |
10 | 10 | "os" |
11 | 11 | "runtime" |
| 12 | + "sync/atomic" |
12 | 13 | "testing" |
13 | 14 | "time" |
14 | 15 |
|
@@ -63,28 +64,28 @@ var labels = map[string]string{ |
63 | 64 | } |
64 | 65 |
|
65 | 66 | func checkContentStoreWriter(ctx context.Context, t *testing.T, cs content.Store) { |
66 | | - c1, d1 := createContent(256, 1) |
| 67 | + c1, d1 := createContent(256) |
67 | 68 | w1, err := cs.Writer(ctx, "c1", 0, "") |
68 | 69 | if err != nil { |
69 | 70 | t.Fatal(err) |
70 | 71 | } |
71 | 72 | defer w1.Close() |
72 | 73 |
|
73 | | - c2, d2 := createContent(256, 2) |
| 74 | + c2, d2 := createContent(256) |
74 | 75 | w2, err := cs.Writer(ctx, "c2", int64(len(c2)), "") |
75 | 76 | if err != nil { |
76 | 77 | t.Fatal(err) |
77 | 78 | } |
78 | 79 | defer w2.Close() |
79 | 80 |
|
80 | | - c3, d3 := createContent(256, 3) |
| 81 | + c3, d3 := createContent(256) |
81 | 82 | w3, err := cs.Writer(ctx, "c3", 0, d3) |
82 | 83 | if err != nil { |
83 | 84 | t.Fatal(err) |
84 | 85 | } |
85 | 86 | defer w3.Close() |
86 | 87 |
|
87 | | - c4, d4 := createContent(256, 4) |
| 88 | + c4, d4 := createContent(256) |
88 | 89 | w4, err := cs.Writer(ctx, "c4", int64(len(c4)), d4) |
89 | 90 | if err != nil { |
90 | 91 | t.Fatal(err) |
@@ -163,7 +164,7 @@ func checkResumeWriter(ctx context.Context, t *testing.T, cs content.Store) { |
163 | 164 |
|
164 | 165 | var ( |
165 | 166 | ref = "cb" |
166 | | - cb, dgst = createContent(256, 10) |
| 167 | + cb, dgst = createContent(256) |
167 | 168 | first, second = cb[:128], cb[128:] |
168 | 169 | ) |
169 | 170 |
|
@@ -223,7 +224,7 @@ func checkResumeWriter(ctx context.Context, t *testing.T, cs content.Store) { |
223 | 224 | } |
224 | 225 |
|
225 | 226 | func checkUploadStatus(ctx context.Context, t *testing.T, cs content.Store) { |
226 | | - c1, d1 := createContent(256, 17) |
| 227 | + c1, d1 := createContent(256) |
227 | 228 |
|
228 | 229 | preStart := time.Now() |
229 | 230 | w1, err := cs.Writer(ctx, "c1", 256, d1) |
@@ -292,7 +293,7 @@ func checkUploadStatus(ctx context.Context, t *testing.T, cs content.Store) { |
292 | 293 | } |
293 | 294 |
|
294 | 295 | func checkLabels(ctx context.Context, t *testing.T, cs content.Store) { |
295 | | - c1, d1 := createContent(256, 19) |
| 296 | + c1, d1 := createContent(256) |
296 | 297 |
|
297 | 298 | w1, err := cs.Writer(ctx, "c1", 256, d1) |
298 | 299 | if err != nil { |
@@ -365,7 +366,7 @@ func checkResume(rf func(context.Context, content.Writer, []byte, int64, int64, |
365 | 366 |
|
366 | 367 | for i, size := range sizes { |
367 | 368 | for j, tp := range truncations { |
368 | | - b, d := createContent(size, int64(i*len(truncations)+j)) |
| 369 | + b, d := createContent(size) |
369 | 370 | limit := int64(float64(size) * tp) |
370 | 371 | ref := fmt.Sprintf("ref-%d-%d", i, j) |
371 | 372 |
|
@@ -548,7 +549,14 @@ func checkInfo(ctx context.Context, cs content.Store, d digest.Digest, expected |
548 | 549 | return nil |
549 | 550 | } |
550 | 551 |
|
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 | + |
552 | 560 | b, err := ioutil.ReadAll(io.LimitReader(rand.New(rand.NewSource(seed)), size)) |
553 | 561 | if err != nil { |
554 | 562 | panic(err) |
|
0 commit comments