diff --git a/services/dedup/badger/badger_test.go b/services/dedup/badger/badger_test.go index 05d7521a8b..81271b0cd7 100644 --- a/services/dedup/badger/badger_test.go +++ b/services/dedup/badger/badger_test.go @@ -1,7 +1,6 @@ package badger import ( - "os" "testing" "github.com/stretchr/testify/require" @@ -18,9 +17,7 @@ func Test_Badger(t *testing.T) { logger.Reset() misc.Init() - dbPath := os.TempDir() + "/dedup_test" - defer func() { _ = os.RemoveAll(dbPath) }() - _ = os.RemoveAll(dbPath) + dbPath := t.TempDir() conf := config.New() t.Setenv("RUDDER_TMPDIR", dbPath) badger := NewBadgerDB(conf, stats.NOP, DefaultPath()) @@ -29,23 +26,23 @@ func Test_Badger(t *testing.T) { t.Run("Same messageID should be deduped from badger", func(t *testing.T) { key1 := types.KeyValue{Key: "a", Value: 1, WorkspaceId: "test"} key2 := types.KeyValue{Key: "a", Value: 1, WorkspaceId: "test"} - found, _, err := badger.Get(key1) - require.Nil(t, err) - require.True(t, found) + notAvailable, _, err := badger.Get(key1) + require.NoError(t, err) + require.True(t, notAvailable) err = badger.Commit([]string{key1.Key}) require.NoError(t, err) - found, _, err = badger.Get(key2) - require.Nil(t, err) - require.False(t, found) + notAvailable, _, err = badger.Get(key2) + require.NoError(t, err) + require.False(t, notAvailable) }) t.Run("Same messageID should be deduped from cache", func(t *testing.T) { key1 := types.KeyValue{Key: "b", Value: 1, WorkspaceId: "test"} key2 := types.KeyValue{Key: "b", Value: 1, WorkspaceId: "test"} found, _, err := badger.Get(key1) - require.Nil(t, err) + require.NoError(t, err) require.True(t, found) found, _, err = badger.Get(key2) - require.Nil(t, err) + require.NoError(t, err) require.False(t, found) }) } diff --git a/services/dedup/dedup_test.go b/services/dedup/dedup_test.go index c6a8aee66b..7b5bd79a9b 100644 --- a/services/dedup/dedup_test.go +++ b/services/dedup/dedup_test.go @@ -51,9 +51,7 @@ func Test_Dedup(t *testing.T) { logger.Reset() misc.Init() - dbPath := os.TempDir() + "/dedup_test" - defer func() { _ = os.RemoveAll(dbPath) }() - _ = os.RemoveAll(dbPath) + dbPath := t.TempDir() conf := config.New() t.Setenv("RUDDER_TMPDIR", dbPath) pool, err := dockertest.NewPool("") @@ -70,7 +68,7 @@ func Test_Dedup(t *testing.T) { t.Run("if message id is not present in cache and badger db", func(t *testing.T) { found, _, err := d.Get(types.KeyValue{Key: "a", Value: 1, WorkspaceId: "test"}) - require.Nil(t, err) + require.NoError(t, err) require.Equal(t, true, found) // Checking it again should give us the previous value from the cache diff --git a/services/dedup/mirrorBadger/mirrorBadger.go b/services/dedup/mirrorBadger/mirrorBadger.go index f67b5476f9..efcd3a6dcd 100644 --- a/services/dedup/mirrorBadger/mirrorBadger.go +++ b/services/dedup/mirrorBadger/mirrorBadger.go @@ -31,6 +31,7 @@ func (mb *MirrorBadger) Close() { } func (mb *MirrorBadger) Get(kv types.KeyValue) (bool, int64, error) { + _, _, _ = mb.scylla.Get(kv) return mb.badger.Get(kv) } diff --git a/services/dedup/mirrorScylla/mirrorScylla.go b/services/dedup/mirrorScylla/mirrorScylla.go index f7117d4518..751534f44b 100644 --- a/services/dedup/mirrorScylla/mirrorScylla.go +++ b/services/dedup/mirrorScylla/mirrorScylla.go @@ -31,6 +31,7 @@ func (ms *MirrorScylla) Close() { } func (ms *MirrorScylla) Get(kv types.KeyValue) (bool, int64, error) { + _, _, _ = ms.badger.Get(kv) return ms.scylla.Get(kv) }