diff --git a/internal/db/db.go b/internal/db/db.go index 6ac3dc8766..197ab493d5 100644 --- a/internal/db/db.go +++ b/internal/db/db.go @@ -151,7 +151,7 @@ func (db *db) NewConcurrentTxn(ctx context.Context, readonly bool) (datastore.Tx return datastore.NewConcurrentTxnFrom(ctx, db.rootstore, txnId, readonly) } -// Root returns the root datastore. +// Rootstore returns the root datastore. func (db *db) Rootstore() datastore.Rootstore { return db.rootstore } diff --git a/internal/db/p2p_replicator_test.go b/internal/db/p2p_replicator_test.go index 732b79a230..b287101a54 100644 --- a/internal/db/p2p_replicator_test.go +++ b/internal/db/p2p_replicator_test.go @@ -92,12 +92,10 @@ func TestSetReplicator_WithValidCollection_ShouldSucceed(t *testing.T) { Schemas: []string{"User"}, }) require.NoError(t, err) - for msg := range sub.Message() { - replicator := msg.Data.(event.Replicator) - require.Equal(t, peer.ID("other"), replicator.Info.ID) - require.Equal(t, map[string]struct{}{schema.Root: {}}, replicator.Schemas) - break - } + msg := <-sub.Message() + replicator := msg.Data.(event.Replicator) + require.Equal(t, peer.ID("other"), replicator.Info.ID) + require.Equal(t, map[string]struct{}{schema.Root: {}}, replicator.Schemas) } func TestSetReplicator_WithValidCollectionsOnSeparateSet_ShouldSucceed(t *testing.T) { @@ -120,12 +118,10 @@ func TestSetReplicator_WithValidCollectionsOnSeparateSet_ShouldSucceed(t *testin Schemas: []string{"User"}, }) require.NoError(t, err) - for msg := range sub.Message() { - replicator := msg.Data.(event.Replicator) - require.Equal(t, peerID, replicator.Info.ID) - require.Equal(t, map[string]struct{}{schema1.Root: {}}, replicator.Schemas) - break - } + msg := <-sub.Message() + replicator := msg.Data.(event.Replicator) + require.Equal(t, peerID, replicator.Info.ID) + require.Equal(t, map[string]struct{}{schema1.Root: {}}, replicator.Schemas) cols2, err := db.AddSchema(ctx, `type Book { name: String }`) require.NoError(t, err) @@ -136,12 +132,10 @@ func TestSetReplicator_WithValidCollectionsOnSeparateSet_ShouldSucceed(t *testin Schemas: []string{"Book"}, }) require.NoError(t, err) - for msg := range sub.Message() { - replicator := msg.Data.(event.Replicator) - require.Equal(t, peerID, replicator.Info.ID) - require.Equal(t, map[string]struct{}{schema1.Root: {}, schema2.Root: {}}, replicator.Schemas) - break - } + msg = <-sub.Message() + replicator = msg.Data.(event.Replicator) + require.Equal(t, peerID, replicator.Info.ID) + require.Equal(t, map[string]struct{}{schema1.Root: {}, schema2.Root: {}}, replicator.Schemas) } func TestSetReplicator_WithValidCollectionWithDoc_ShouldSucceed(t *testing.T) { @@ -165,14 +159,12 @@ func TestSetReplicator_WithValidCollectionWithDoc_ShouldSucceed(t *testing.T) { Schemas: []string{"User"}, }) require.NoError(t, err) - for msg := range sub.Message() { - replicator := msg.Data.(event.Replicator) - require.Equal(t, peer.ID("other"), replicator.Info.ID) - require.Equal(t, map[string]struct{}{col.SchemaRoot(): {}}, replicator.Schemas) - for docEvt := range replicator.Docs { - require.Equal(t, doc.ID().String(), docEvt.DocID) - } - break + msg := <-sub.Message() + replicator := msg.Data.(event.Replicator) + require.Equal(t, peer.ID("other"), replicator.Info.ID) + require.Equal(t, map[string]struct{}{col.SchemaRoot(): {}}, replicator.Schemas) + for docEvt := range replicator.Docs { + require.Equal(t, doc.ID().String(), docEvt.DocID) } } @@ -214,20 +206,16 @@ func TestDeleteReplicator_WithValidCollection_ShouldSucceed(t *testing.T) { Schemas: []string{"User"}, }) require.NoError(t, err) - for msg := range sub.Message() { - replicator := msg.Data.(event.Replicator) - require.Equal(t, peerID, replicator.Info.ID) - require.Equal(t, map[string]struct{}{schema.Root: {}}, replicator.Schemas) - break - } + msg := <-sub.Message() + replicator := msg.Data.(event.Replicator) + require.Equal(t, peerID, replicator.Info.ID) + require.Equal(t, map[string]struct{}{schema.Root: {}}, replicator.Schemas) err = db.DeleteReplicator(ctx, client.Replicator{Info: peer.AddrInfo{ID: peerID}}) require.NoError(t, err) - for msg := range sub.Message() { - replicator := msg.Data.(event.Replicator) - require.Equal(t, peerID, replicator.Info.ID) - require.Equal(t, map[string]struct{}{}, replicator.Schemas) - break - } + msg = <-sub.Message() + replicator = msg.Data.(event.Replicator) + require.Equal(t, peerID, replicator.Info.ID) + require.Equal(t, map[string]struct{}{}, replicator.Schemas) } func TestDeleteReplicator_PartialWithValidCollections_ShouldSucceed(t *testing.T) { @@ -254,20 +242,17 @@ func TestDeleteReplicator_PartialWithValidCollections_ShouldSucceed(t *testing.T Schemas: []string{"User", "Book"}, }) require.NoError(t, err) - for msg := range sub.Message() { - replicator := msg.Data.(event.Replicator) - require.Equal(t, peerID, replicator.Info.ID) - require.Equal(t, map[string]struct{}{schema1.Root: {}, schema2.Root: {}}, replicator.Schemas) - break - } + msg := <-sub.Message() + replicator := msg.Data.(event.Replicator) + require.Equal(t, peerID, replicator.Info.ID) + require.Equal(t, map[string]struct{}{schema1.Root: {}, schema2.Root: {}}, replicator.Schemas) + err = db.DeleteReplicator(ctx, client.Replicator{Info: peer.AddrInfo{ID: peerID}, Schemas: []string{"User"}}) require.NoError(t, err) - for msg := range sub.Message() { - replicator := msg.Data.(event.Replicator) - require.Equal(t, peerID, replicator.Info.ID) - require.Equal(t, map[string]struct{}{schema2.Root: {}}, replicator.Schemas) - break - } + msg = <-sub.Message() + replicator = msg.Data.(event.Replicator) + require.Equal(t, peerID, replicator.Info.ID) + require.Equal(t, map[string]struct{}{schema2.Root: {}}, replicator.Schemas) } func TestGetAllReplicators_WithValidCollection_ShouldSucceed(t *testing.T) { @@ -290,12 +275,10 @@ func TestGetAllReplicators_WithValidCollection_ShouldSucceed(t *testing.T) { Schemas: []string{"User"}, }) require.NoError(t, err) - for msg := range sub.Message() { - replicator := msg.Data.(event.Replicator) - require.Equal(t, peerID, replicator.Info.ID) - require.Equal(t, map[string]struct{}{schema.Root: {}}, replicator.Schemas) - break - } + msg := <-sub.Message() + replicator := msg.Data.(event.Replicator) + require.Equal(t, peerID, replicator.Info.ID) + require.Equal(t, map[string]struct{}{schema.Root: {}}, replicator.Schemas) reps, err := db.GetAllReplicators(ctx) require.NoError(t, err) @@ -323,19 +306,15 @@ func TestLoadReplicators_WithValidCollection_ShouldSucceed(t *testing.T) { Schemas: []string{"User"}, }) require.NoError(t, err) - for msg := range sub.Message() { - replicator := msg.Data.(event.Replicator) - require.Equal(t, peerID, replicator.Info.ID) - require.Equal(t, map[string]struct{}{schema.Root: {}}, replicator.Schemas) - break - } + msg := <-sub.Message() + replicator := msg.Data.(event.Replicator) + require.Equal(t, peerID, replicator.Info.ID) + require.Equal(t, map[string]struct{}{schema.Root: {}}, replicator.Schemas) err = db.loadAndPublishReplicators(ctx) require.NoError(t, err) - for msg := range sub.Message() { - replicator := msg.Data.(event.Replicator) - require.Equal(t, peerID, replicator.Info.ID) - require.Equal(t, map[string]struct{}{schema.Root: {}}, replicator.Schemas) - break - } + msg = <-sub.Message() + replicator = msg.Data.(event.Replicator) + require.Equal(t, peerID, replicator.Info.ID) + require.Equal(t, map[string]struct{}{schema.Root: {}}, replicator.Schemas) } diff --git a/internal/db/p2p_schema_root_test.go b/internal/db/p2p_schema_root_test.go index b992053257..8039f815b0 100644 --- a/internal/db/p2p_schema_root_test.go +++ b/internal/db/p2p_schema_root_test.go @@ -227,7 +227,6 @@ func TestLoadP2PCollection_WithValidCollectionsAndDocs_ShouldSucceed(t *testing. msg = <-sub.Message() p2pTopic = msg.Data.(event.P2PTopic) require.Equal(t, []string{doc2.ID().String()}, p2pTopic.ToAdd) - } func TestGetAllP2PCollections_WithMultipleValidCollections_ShouldSucceed(t *testing.T) { diff --git a/tests/bench/bench_util.go b/tests/bench/bench_util.go index 5993ee50f8..a574088148 100644 --- a/tests/bench/bench_util.go +++ b/tests/bench/bench_util.go @@ -216,7 +216,7 @@ func NewTestDB(ctx context.Context, t testing.TB) (client.DB, error) { func NewTestStorage(ctx context.Context, t testing.TB) (ds.Batching, error) { dbi, err := newBenchStoreInfo(ctx, t) - return dbi.Root(), err + return dbi.Rootstore(), err } func newBenchStoreInfo(ctx context.Context, t testing.TB) (client.DB, error) { diff --git a/tests/integration/db.go b/tests/integration/db.go index 0928f3b90b..dbbbed7ffb 100644 --- a/tests/integration/db.go +++ b/tests/integration/db.go @@ -97,10 +97,10 @@ func NewBadgerFileDB(ctx context.Context, t testing.TB) (client.DB, error) { return node.DB, err } -// setupDatabase returns the database implementation for the current +// setupNode returns the database implementation for the current // testing state. The database type on the test state is used to // select the datastore implementation to use. -func setupDatabase(s *state) (*node.Node, string, error) { +func setupNode(s *state) (*node.Node, string, error) { opts := []node.Option{ node.WithLensPoolSize(lensPoolSize), // The test framework sets this up elsewhere when required so that it may be wrapped diff --git a/tests/integration/utils2.go b/tests/integration/utils2.go index 1f11bba596..eca87772a1 100644 --- a/tests/integration/utils2.go +++ b/tests/integration/utils2.go @@ -649,10 +649,10 @@ func setStartingNodes( // If nodes have not been explicitly configured via actions, setup a default one. if !hasExplicitNode { - db, path, err := setupDatabase(s) + node, path, err := setupNode(s) require.Nil(s.t, err) - c, err := setupClient(s, db) + c, err := setupClient(s, node) require.Nil(s.t, err) s.nodes = append(s.nodes, c) @@ -673,7 +673,7 @@ func restartNodes( for i := len(s.nodes) - 1; i >= 0; i-- { originalPath := databaseDir databaseDir = s.dbPaths[i] - node, _, err := setupDatabase(s) + node, _, err := setupNode(s) require.Nil(s.t, err) databaseDir = originalPath @@ -787,7 +787,7 @@ func configureNode( return } - node, path, err := setupDatabase(s) //disable change dector, or allow it? + node, path, err := setupNode(s) //disable change dector, or allow it? require.NoError(s.t, err) privateKey, err := crypto.GenerateEd25519()