From a46881fc27b29c072b9b692d1f3608e0abaa93d9 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Sat, 6 Nov 2021 09:50:38 -0400 Subject: [PATCH] fix: rebase issues --- waku/persistence/store.go | 2 +- waku/persistence/store_test.go | 21 +++++++-------------- waku/v2/protocol/store/waku_store.go | 2 +- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/waku/persistence/store.go b/waku/persistence/store.go index da96ea1c..e1a4fb2e 100644 --- a/waku/persistence/store.go +++ b/waku/persistence/store.go @@ -109,7 +109,7 @@ func (d *DBStore) cleanOlderRecords() error { // Delete older messages if d.maxDuration > 0 { sqlStmt := `DELETE FROM message WHERE receiverTimestamp < ?` - _, err := d.db.Exec(sqlStmt, utils.GetUnixEpochFrom(func() time.Time { return time.Now().Add(-d.maxDuration) })) + _, err := d.db.Exec(sqlStmt, utils.GetUnixEpochFrom(time.Now().Add(-d.maxDuration))) if err != nil { return err } diff --git a/waku/persistence/store_test.go b/waku/persistence/store_test.go index b0f34223..fabdc6fe 100644 --- a/waku/persistence/store_test.go +++ b/waku/persistence/store_test.go @@ -9,7 +9,6 @@ import ( _ "github.com/mattn/go-sqlite3" // Blank import to register the sqlite3 driver "github.com/status-im/go-waku/tests" "github.com/status-im/go-waku/waku/v2/protocol/pb" - "github.com/status-im/go-waku/waku/v2/utils" "github.com/stretchr/testify/require" ) @@ -59,24 +58,18 @@ func TestStoreRetention(t *testing.T) { insertTime := time.Now() - fnTime := func(t1 time.Duration) float64 { - return utils.GetUnixEpochFrom(func() time.Time { - return insertTime.Add(t1) - }) - } - - _ = store.Put(createIndex([]byte{1}, fnTime(-70*time.Second)), "test", tests.CreateWakuMessage("test", 1)) - _ = store.Put(createIndex([]byte{2}, fnTime(-60*time.Second)), "test", tests.CreateWakuMessage("test", 2)) - _ = store.Put(createIndex([]byte{3}, fnTime(-50*time.Second)), "test", tests.CreateWakuMessage("test", 3)) - _ = store.Put(createIndex([]byte{4}, fnTime(-40*time.Second)), "test", tests.CreateWakuMessage("test", 4)) - _ = store.Put(createIndex([]byte{5}, fnTime(-30*time.Second)), "test", tests.CreateWakuMessage("test", 5)) + _ = store.Put(createIndex([]byte{1}, float64(insertTime.Add(-70*time.Second).Unix())), "test", tests.CreateWakuMessage("test", 1)) + _ = store.Put(createIndex([]byte{2}, float64(insertTime.Add(-60*time.Second).Unix())), "test", tests.CreateWakuMessage("test", 2)) + _ = store.Put(createIndex([]byte{3}, float64(insertTime.Add(-50*time.Second).Unix())), "test", tests.CreateWakuMessage("test", 3)) + _ = store.Put(createIndex([]byte{4}, float64(insertTime.Add(-40*time.Second).Unix())), "test", tests.CreateWakuMessage("test", 4)) + _ = store.Put(createIndex([]byte{5}, float64(insertTime.Add(-30*time.Second).Unix())), "test", tests.CreateWakuMessage("test", 5)) dbResults, err := store.GetAll() require.NoError(t, err) require.Len(t, dbResults, 5) - _ = store.Put(createIndex([]byte{6}, fnTime(-20*time.Second)), "test", tests.CreateWakuMessage("test", 6)) - _ = store.Put(createIndex([]byte{7}, fnTime(-10*time.Second)), "test", tests.CreateWakuMessage("test", 7)) + _ = store.Put(createIndex([]byte{6}, float64(insertTime.Add(-20*time.Second).Unix())), "test", tests.CreateWakuMessage("test", 6)) + _ = store.Put(createIndex([]byte{7}, float64(insertTime.Add(-10*time.Second).Unix())), "test", tests.CreateWakuMessage("test", 7)) // This step simulates starting go-waku again from scratch diff --git a/waku/v2/protocol/store/waku_store.go b/waku/v2/protocol/store/waku_store.go index ba04c2a3..cfa055c3 100644 --- a/waku/v2/protocol/store/waku_store.go +++ b/waku/v2/protocol/store/waku_store.go @@ -145,7 +145,7 @@ func (store *WakuStore) FindMessages(query *pb.HistoryQuery) *pb.HistoryResponse result := new(pb.HistoryResponse) // data holds IndexedWakuMessage whose topics match the query var data []IndexedWakuMessage - for _, indexedMsg := range w.messageQueue.messages { + for _, indexedMsg := range store.messageQueue.messages { // temporal filtering // check whether the history query contains a time filter if query.StartTime != 0 && query.EndTime != 0 {