-
Notifications
You must be signed in to change notification settings - Fork 110
swarm/network/stream: refactor bootstrapping of tests #1176
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,6 @@ package stream | |
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"sync" | ||
"testing" | ||
"time" | ||
|
@@ -27,7 +26,6 @@ import ( | |
"github.com/ethereum/go-ethereum/p2p/enode" | ||
"github.com/ethereum/go-ethereum/p2p/simulations/adapters" | ||
"github.com/ethereum/go-ethereum/swarm/log" | ||
"github.com/ethereum/go-ethereum/swarm/network" | ||
"github.com/ethereum/go-ethereum/swarm/network/simulation" | ||
"github.com/ethereum/go-ethereum/swarm/state" | ||
"github.com/ethereum/go-ethereum/swarm/storage" | ||
|
@@ -105,43 +103,25 @@ func TestRetrieval(t *testing.T) { | |
} | ||
|
||
var retrievalSimServiceMap = map[string]simulation.ServiceFunc{ | ||
"streamer": retrievalStreamerFunc, | ||
} | ||
|
||
func retrievalStreamerFunc(ctx *adapters.ServiceContext, bucket *sync.Map) (s node.Service, cleanup func(), err error) { | ||
n := ctx.Config.Node() | ||
addr := network.NewAddr(n) | ||
store, datadir, err := createTestLocalStorageForID(n.ID(), addr) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
bucket.Store(bucketKeyStore, store) | ||
|
||
localStore := store.(*storage.LocalStore) | ||
netStore, err := storage.NewNetStore(localStore, nil) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
kad := network.NewKademlia(addr.Over(), network.NewKadParams()) | ||
delivery := NewDelivery(kad, netStore) | ||
netStore.NewNetFetcherFunc = network.NewFetcherFactory(delivery.RequestFromPeers, true).New | ||
|
||
r := NewRegistry(addr.ID(), delivery, netStore, state.NewInmemoryStore(), &RegistryOptions{ | ||
Retrieval: RetrievalEnabled, | ||
Syncing: SyncingAutoSubscribe, | ||
SyncUpdateDelay: 3 * time.Second, | ||
}, nil) | ||
"streamer": func(ctx *adapters.ServiceContext, bucket *sync.Map) (s node.Service, cleanup func(), err error) { | ||
addr, netStore, delivery, clean, err := newNetStoreAndDelivery(ctx, bucket) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
fileStore := storage.NewFileStore(netStore, storage.NewFileStoreParams()) | ||
bucket.Store(bucketKeyFileStore, fileStore) | ||
r := NewRegistry(addr.ID(), delivery, netStore, state.NewInmemoryStore(), &RegistryOptions{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if we'd just add a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @holisticode we override the registry in some of the tests, this is why I didn't do it - its not just the Personally I think even the current constructors are a bit too complicated, but this is because of the high coupling between the interfaces... The current solution is far from ideal, I just hope it bring slightly better defaults. |
||
Retrieval: RetrievalEnabled, | ||
Syncing: SyncingAutoSubscribe, | ||
SyncUpdateDelay: 3 * time.Second, | ||
}, nil) | ||
|
||
cleanup = func() { | ||
os.RemoveAll(datadir) | ||
netStore.Close() | ||
r.Close() | ||
} | ||
cleanup = func() { | ||
r.Close() | ||
clean() | ||
} | ||
|
||
return r, cleanup, nil | ||
return r, cleanup, nil | ||
}, | ||
} | ||
|
||
/* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@janos I am pretty sure this doesn't work, but haven't tried it just yet. Not sure how we cast a mock store to
*storage.LocalStore
further down, but this is how it is in the current code as well.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have found that mock store in stream tests were broken after some rewrite. I am not sure if they were fixed. Maybe @holisticode have more details, but I will have a look also.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But it is important that mock store is not casted to LocalStore, there were numerous discussion on this, but injected down to ldbstore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least now we have to fix it at one place, and not at multiple :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MockStore is working correctly here, but naming is confusing.
createMockStore
does not create mock store, it creates new localstore with injected mockstore. It is similar tocreateTestLocalStorageForID
, so maybe to rename this function tocreateTestLocalStoreWithMockStore
, ornewLocalStoreWithMock
, and to move it from syncer_test.go to common_test.go. BTW, the description of this flag is completely wrong, it is false by default.