From 01ffc86e34f5b245bb58dc2316f84724ca6aa45e Mon Sep 17 00:00:00 2001 From: Fred Carle Date: Fri, 16 Dec 2022 00:40:22 -0500 Subject: [PATCH] change to defra in-memory datastore --- datastore/txn.go | 2 +- db/fetcher/versioned.go | 1 - tests/integration/explain/utils.go | 2 +- .../subscription/subscription_test.go | 6 ------ tests/integration/utils.go | 18 +++++++++++------- 5 files changed, 13 insertions(+), 16 deletions(-) diff --git a/datastore/txn.go b/datastore/txn.go index 8e344a546e..7ddbd95d8b 100644 --- a/datastore/txn.go +++ b/datastore/txn.go @@ -69,7 +69,7 @@ func NewTxnFrom(ctx context.Context, rootstore ds.TxnDatastore, readonly bool) ( return nil, err } - root := AsDSReaderWriter(txnStore) + root := AsDSReaderWriter(rootstore) multistore := MultiStoreFrom(root) return &txn{ rootTxn, diff --git a/db/fetcher/versioned.go b/db/fetcher/versioned.go index 6883b5c432..48fa6a5fde 100644 --- a/db/fetcher/versioned.go +++ b/db/fetcher/versioned.go @@ -15,7 +15,6 @@ import ( "context" "fmt" - badger "github.com/dgraph-io/badger/v3" "github.com/ipfs/go-cid" ds "github.com/ipfs/go-datastore" format "github.com/ipfs/go-ipld-format" diff --git a/tests/integration/explain/utils.go b/tests/integration/explain/utils.go index 8c72bcd4c0..e3642882a3 100644 --- a/tests/integration/explain/utils.go +++ b/tests/integration/explain/utils.go @@ -129,7 +129,7 @@ func ExecuteExplainRequestTestCase( } ctx := context.Background() - dbs, err := testUtils.GetDatabases(ctx, t, false) + dbs, err := testUtils.GetDatabases(ctx, t) if testUtils.AssertError(t, explainTest.Description, err, explainTest.ExpectedError) { return } diff --git a/tests/integration/subscription/subscription_test.go b/tests/integration/subscription/subscription_test.go index 4df570d857..2c1ba42e70 100644 --- a/tests/integration/subscription/subscription_test.go +++ b/tests/integration/subscription/subscription_test.go @@ -60,7 +60,6 @@ func TestSubscriptionWithCreateMutations(t *testing.T) { }, }, }, - DisableMapStore: true, } executeTestCase(t, test) @@ -94,7 +93,6 @@ func TestSubscriptionWithFilterAndOneCreateMutation(t *testing.T) { }, }, }, - DisableMapStore: true, } executeTestCase(t, test) @@ -122,7 +120,6 @@ func TestSubscriptionWithFilterAndOneCreateMutationOutsideFilter(t *testing.T) { ExpectedTimout: true, }, }, - DisableMapStore: true, } executeTestCase(t, test) @@ -166,7 +163,6 @@ func TestSubscriptionWithFilterAndCreateMutations(t *testing.T) { ExpectedTimout: true, }, }, - DisableMapStore: true, } executeTestCase(t, test) @@ -218,7 +214,6 @@ func TestSubscriptionWithUpdateMutations(t *testing.T) { }, }, }, - DisableMapStore: true, } executeTestCase(t, test) @@ -276,7 +271,6 @@ func TestSubscriptionWithUpdateAllMutations(t *testing.T) { }, }, }, - DisableMapStore: true, } executeTestCase(t, test) diff --git a/tests/integration/utils.go b/tests/integration/utils.go index d6166c669e..39d0e36476 100644 --- a/tests/integration/utils.go +++ b/tests/integration/utils.go @@ -42,6 +42,7 @@ const ( memoryBadgerEnvName = "DEFRA_BADGER_MEMORY" fileBadgerEnvName = "DEFRA_BADGER_FILE" fileBadgerPathEnvName = "DEFRA_BADGER_FILE_PATH" + inMemoryEnvName = "DEFRA_IN_MEMORY" setupOnlyEnvName = "DEFRA_SETUP_ONLY" detectDbChangesEnvName = "DEFRA_DETECT_DATABASE_CHANGES" repositoryEnvName = "DEFRA_CODE_REPOSITORY" @@ -66,6 +67,7 @@ var ( log = logging.MustNewLogger("defra.tests.integration") badgerInMemory bool badgerFile bool + inMemoryStore bool ) const subsciptionTimeout = 1 * time.Second @@ -174,12 +176,14 @@ func init() { badgerInMemoryValue, _ := os.LookupEnv(memoryBadgerEnvName) databaseDir, _ = os.LookupEnv(fileBadgerPathEnvName) detectDbChangesValue, _ := os.LookupEnv(detectDbChangesEnvName) + inMemoryStoreValue, _ := os.LookupEnv(inMemoryEnvName) repositoryValue, repositorySpecified := os.LookupEnv(repositoryEnvName) setupOnlyValue, _ := os.LookupEnv(setupOnlyEnvName) targetBranchValue, targetBranchSpecified := os.LookupEnv(targetBranchEnvName) badgerFile = getBool(badgerFileValue) badgerInMemory = getBool(badgerInMemoryValue) + inMemoryStore = getBool(inMemoryStoreValue) DetectDbChanges = getBool(detectDbChangesValue) SetupOnly = getBool(setupOnlyValue) @@ -192,7 +196,7 @@ func init() { } // default is to run against all - if !badgerInMemory && !badgerFile && !mapStore && !DetectDbChanges { + if !badgerInMemory && !badgerFile && !inMemoryStore && !DetectDbChanges { badgerInMemory = true // Testing against the file system is off by default badgerFile = false @@ -250,7 +254,7 @@ func NewBadgerMemoryDB(ctx context.Context, dbopts ...db.Option) (databaseInfo, }, nil } -func NewMapDB(ctx context.Context) (databaseInfo, error) { +func NewInMemoryDB(ctx context.Context) (databaseInfo, error) { rootstore := memory.NewDatastore(ctx) db, err := db.NewDB(ctx, rootstore, db.WithUpdateEvents()) if err != nil { @@ -295,7 +299,7 @@ func newBadgerFileDB(ctx context.Context, t testing.TB, path string) (databaseIn }, nil } -func GetDatabases(ctx context.Context, t *testing.T, disableMapStore bool) ([]databaseInfo, error) { +func GetDatabases(ctx context.Context, t *testing.T) ([]databaseInfo, error) { databases := []databaseInfo{} if badgerInMemory { @@ -314,12 +318,12 @@ func GetDatabases(ctx context.Context, t *testing.T, disableMapStore bool) ([]da databases = append(databases, badgerIMDatabase) } - if !disableMapStore && mapStore { - mapDatabase, err := NewMapDB(ctx) + if inMemoryStore { + inMemoryDatabase, err := NewInMemoryDB(ctx) if err != nil { return nil, err } - databases = append(databases, mapDatabase) + databases = append(databases, inMemoryDatabase) } return databases, nil @@ -343,7 +347,7 @@ func ExecuteQueryTestCase( } ctx := context.Background() - dbs, err := GetDatabases(ctx, t, test.DisableMapStore) + dbs, err := GetDatabases(ctx, t) if AssertError(t, test.Description, err, test.ExpectedError) { return }