Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use MapDatastore for provider backend tests instead of leveldb #896

Merged
merged 2 commits into from
Sep 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 2 additions & 13 deletions v2/backend_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/benbjohnson/clock"
ds "github.com/ipfs/go-datastore"
syncds "github.com/ipfs/go-datastore/sync"
"github.com/libp2p/go-libp2p"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand All @@ -21,9 +22,7 @@ func newBackendProvider(t testing.TB, cfg *ProvidersBackendConfig) *ProvidersBac
h, err := libp2p.New(libp2p.NoListenAddrs)
require.NoError(t, err)

dstore, err := InMemoryDatastore()
require.NoError(t, err)

dstore := syncds.MutexWrap(ds.NewMapDatastore())
t.Cleanup(func() {
if err = dstore.Close(); err != nil {
t.Logf("closing datastore: %s", err)
Expand Down Expand Up @@ -71,23 +70,13 @@ func TestProvidersBackend_GarbageCollection(t *testing.T) {
// advance clock half the validity time and check if record is still there
clk.Add(cfg.ProvideValidity / 2)

// sync datastore to have all put/deletes visible
err = b.datastore.Sync(ctx, ds.NewKey("/"))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

require.NoError(t, err)

// we expect the record to still be there after half the ProvideValidity
_, err = b.datastore.Get(ctx, dsKey)
require.NoError(t, err)

// advance clock another time and check if the record was GC'd now
clk.Add(cfg.ProvideValidity + cfg.GCInterval)

// sync datastore to have all put/deletes visible
err = b.datastore.Sync(ctx, ds.NewKey("/"))
require.NoError(t, err)

clk.Add(time.Minute)

// we expect the record to be GC'd now
val, err := b.datastore.Get(ctx, dsKey)
assert.ErrorIs(t, err, ds.ErrNotFound)
Expand Down