fix race conditions in tests
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
Jeromy committed
Feb 11, 2016 at 11:09 UTC
abadc94e23d128319e11ee5332f25a9be7c31650
2 files changed
+9
-5
namesys/resolve_test.go
+7
-4
@@ -6,6 +6,7 @@ import (
6
"time"
7
8
ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
9
+ dssync "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/sync"
10
key "github.com/ipfs/go-ipfs/blocks/key"
11
path "github.com/ipfs/go-ipfs/path"
12
mockrouting "github.com/ipfs/go-ipfs/routing/mock"
@@ -16,8 +17,10 @@ import (
17
)
18
19
func TestRoutingResolve(t *testing.T) {
19
- d := mockrouting.NewServer().Client(testutil.RandIdentityOrFatal(t))
20
- dstore := ds.NewMapDatastore()
20
+ dstore := dssync.MutexWrap(ds.NewMapDatastore())
21
+ serv := mockrouting.NewServer()
22
+ id := testutil.RandIdentityOrFatal(t)
23
+ d := serv.ClientWithDatastore(context.Background(), id, dstore)
24
25
resolver := NewRoutingResolver(d, 0)
26
publisher := NewRoutingPublisher(d, dstore)
@@ -50,7 +53,7 @@ func TestRoutingResolve(t *testing.T) {
53
}
54
55
func TestPrexistingExpiredRecord(t *testing.T) {
53
- dstore := ds.NewMapDatastore()
56
+ dstore := dssync.MutexWrap(ds.NewMapDatastore())
57
d := mockrouting.NewServer().ClientWithDatastore(context.Background(), testutil.RandIdentityOrFatal(t), dstore)
58
59
resolver := NewRoutingResolver(d, 0)
@@ -87,7 +90,7 @@ func TestPrexistingExpiredRecord(t *testing.T) {
90
}
91
92
func TestPrexistingRecord(t *testing.T) {
90
- dstore := ds.NewMapDatastore()
93
+ dstore := dssync.MutexWrap(ds.NewMapDatastore())
94
d := mockrouting.NewServer().ClientWithDatastore(context.Background(), testutil.RandIdentityOrFatal(t), dstore)
95
96
resolver := NewRoutingResolver(d, 0)
routing/mock/centralized_server.go
+2
-1
@@ -6,6 +6,7 @@ import (
6
"time"
7
8
ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
9
+ dssync "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/sync"
10
key "github.com/ipfs/go-ipfs/blocks/key"
11
"github.com/ipfs/go-ipfs/util/testutil"
12
peer "gx/ipfs/QmUBogf4nUefBjmYjn6jfsfPJRkmDGSeMhNj4usRKq69f4/go-libp2p/p2p/peer"
@@ -74,7 +75,7 @@ func (rs *s) Providers(k key.Key) []peer.PeerInfo {
75
}
76
77
func (rs *s) Client(p testutil.Identity) Client {
77
- return rs.ClientWithDatastore(context.Background(), p, ds.NewMapDatastore())
78
+ return rs.ClientWithDatastore(context.Background(), p, dssync.MutexWrap(ds.NewMapDatastore()))
79
}
80
81
func (rs *s) ClientWithDatastore(_ context.Context, p testutil.Identity, datastore ds.Datastore) Client {