From abadc94e23d128319e11ee5332f25a9be7c31650 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Thu, 11 Feb 2016 11:09:09 -0800 Subject: [PATCH] fix race conditions in tests License: MIT Signed-off-by: Jeromy --- namesys/resolve_test.go | 11 +++++++---- routing/mock/centralized_server.go | 3 ++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/namesys/resolve_test.go b/namesys/resolve_test.go index ff1b27f54..555b3055a 100644 --- a/namesys/resolve_test.go +++ b/namesys/resolve_test.go @@ -6,6 +6,7 @@ import ( "time" ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore" + dssync "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/sync" key "github.com/ipfs/go-ipfs/blocks/key" path "github.com/ipfs/go-ipfs/path" mockrouting "github.com/ipfs/go-ipfs/routing/mock" @@ -16,8 +17,10 @@ import ( ) func TestRoutingResolve(t *testing.T) { - d := mockrouting.NewServer().Client(testutil.RandIdentityOrFatal(t)) - dstore := ds.NewMapDatastore() + dstore := dssync.MutexWrap(ds.NewMapDatastore()) + serv := mockrouting.NewServer() + id := testutil.RandIdentityOrFatal(t) + d := serv.ClientWithDatastore(context.Background(), id, dstore) resolver := NewRoutingResolver(d, 0) publisher := NewRoutingPublisher(d, dstore) @@ -50,7 +53,7 @@ func TestRoutingResolve(t *testing.T) { } func TestPrexistingExpiredRecord(t *testing.T) { - dstore := ds.NewMapDatastore() + dstore := dssync.MutexWrap(ds.NewMapDatastore()) d := mockrouting.NewServer().ClientWithDatastore(context.Background(), testutil.RandIdentityOrFatal(t), dstore) resolver := NewRoutingResolver(d, 0) @@ -87,7 +90,7 @@ func TestPrexistingExpiredRecord(t *testing.T) { } func TestPrexistingRecord(t *testing.T) { - dstore := ds.NewMapDatastore() + dstore := dssync.MutexWrap(ds.NewMapDatastore()) d := mockrouting.NewServer().ClientWithDatastore(context.Background(), testutil.RandIdentityOrFatal(t), dstore) resolver := NewRoutingResolver(d, 0) diff --git a/routing/mock/centralized_server.go b/routing/mock/centralized_server.go index 8e8d5d0b2..c05ca9460 100644 --- a/routing/mock/centralized_server.go +++ b/routing/mock/centralized_server.go @@ -6,6 +6,7 @@ import ( "time" ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore" + dssync "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore/sync" key "github.com/ipfs/go-ipfs/blocks/key" "github.com/ipfs/go-ipfs/util/testutil" peer "gx/ipfs/QmUBogf4nUefBjmYjn6jfsfPJRkmDGSeMhNj4usRKq69f4/go-libp2p/p2p/peer" @@ -74,7 +75,7 @@ func (rs *s) Providers(k key.Key) []peer.PeerInfo { } func (rs *s) Client(p testutil.Identity) Client { - return rs.ClientWithDatastore(context.Background(), p, ds.NewMapDatastore()) + return rs.ClientWithDatastore(context.Background(), p, dssync.MutexWrap(ds.NewMapDatastore())) } func (rs *s) ClientWithDatastore(_ context.Context, p testutil.Identity, datastore ds.Datastore) Client {