Skip to content

Commit

Permalink
change to defra in-memory datastore
Browse files Browse the repository at this point in the history
  • Loading branch information
fredcarle committed Dec 16, 2022
1 parent 9a51cb3 commit 01ffc86
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 16 deletions.
2 changes: 1 addition & 1 deletion datastore/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion db/fetcher/versioned.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/explain/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 0 additions & 6 deletions tests/integration/subscription/subscription_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ func TestSubscriptionWithCreateMutations(t *testing.T) {
},
},
},
DisableMapStore: true,
}

executeTestCase(t, test)
Expand Down Expand Up @@ -94,7 +93,6 @@ func TestSubscriptionWithFilterAndOneCreateMutation(t *testing.T) {
},
},
},
DisableMapStore: true,
}

executeTestCase(t, test)
Expand Down Expand Up @@ -122,7 +120,6 @@ func TestSubscriptionWithFilterAndOneCreateMutationOutsideFilter(t *testing.T) {
ExpectedTimout: true,
},
},
DisableMapStore: true,
}

executeTestCase(t, test)
Expand Down Expand Up @@ -166,7 +163,6 @@ func TestSubscriptionWithFilterAndCreateMutations(t *testing.T) {
ExpectedTimout: true,
},
},
DisableMapStore: true,
}

executeTestCase(t, test)
Expand Down Expand Up @@ -218,7 +214,6 @@ func TestSubscriptionWithUpdateMutations(t *testing.T) {
},
},
},
DisableMapStore: true,
}

executeTestCase(t, test)
Expand Down Expand Up @@ -276,7 +271,6 @@ func TestSubscriptionWithUpdateAllMutations(t *testing.T) {
},
},
},
DisableMapStore: true,
}

executeTestCase(t, test)
Expand Down
18 changes: 11 additions & 7 deletions tests/integration/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -66,6 +67,7 @@ var (
log = logging.MustNewLogger("defra.tests.integration")
badgerInMemory bool
badgerFile bool
inMemoryStore bool
)

const subsciptionTimeout = 1 * time.Second
Expand Down Expand Up @@ -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)

Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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
}
Expand Down

0 comments on commit 01ffc86

Please sign in to comment.