@@ -3,9 +3,11 @@ package crdt
33import (
44 "bytes"
55 "context"
6+ "math/rand"
67 "reflect"
78 "sort"
89 "testing"
10+ "time"
911
1012 "github.com/ipfs/go-cid"
1113 ds "github.com/ipfs/go-datastore"
@@ -15,6 +17,8 @@ import (
1517
1618var headsTestNS = ds .NewKey ("headstest" )
1719
20+ var randg = rand .New (rand .NewSource (time .Now ().UnixNano ()))
21+
1822// TODO we should also test with a non-batching store
1923func newTestHeads (t * testing.T ) * heads {
2024 t .Helper ()
@@ -32,7 +36,7 @@ func newTestHeads(t *testing.T) *heads {
3236func newCID (t * testing.T ) cid.Cid {
3337 t .Helper ()
3438 var buf [32 ]byte
35- _ , _ = randGen .Read (buf [:])
39+ _ , _ = randg .Read (buf [:])
3640
3741 mh , err := multihash .Sum (buf [:], multihash .SHA2_256 , - 1 )
3842 if err != nil {
@@ -56,7 +60,7 @@ func TestHeadsBasic(t *testing.T) {
5660 cidHeights := make (map [cid.Cid ]uint64 )
5761 numHeads := 5
5862 for i := 0 ; i < numHeads ; i ++ {
59- c , height := newCID (t ), uint64 (randGen .Int ())
63+ c , height := newCID (t ), uint64 (randg .Int ())
6064 cidHeights [c ] = height
6165 err := heads .Add (ctx , c , height )
6266 if err != nil {
@@ -67,7 +71,7 @@ func TestHeadsBasic(t *testing.T) {
6771 assertHeads (t , heads , cidHeights )
6872
6973 for c := range cidHeights {
70- newC , newHeight := newCID (t ), uint64 (randGen .Int ())
74+ newC , newHeight := newCID (t ), uint64 (randg .Int ())
7175 err := heads .Replace (ctx , c , newC , newHeight )
7276 if err != nil {
7377 t .Fatal (err )
0 commit comments