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

[Testing] Load latest version of IAVL tree right after flushed #1621

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Changes from 2 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
39 changes: 39 additions & 0 deletions store/iavlstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package store

import (
"bytes"
"fmt"
"os"
"strconv"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -144,6 +146,43 @@ func testNormal(t *testing.T) {
diskDb.Close()
}

func TestLoadIAVLVersion(t *testing.T) {
flushInterval = int64(5)
memDB := db.NewMemDB()
store, err := NewIAVLStore(memDB, 0, 0, flushInterval)
require.NoError(t, err)
var lastVersion int64
var s string
ch := make(chan int64)
go func() {
for i := int64(1); i <= flushInterval*10000; i++ {
s = strconv.FormatInt(i, 10)
store.Set([]byte("key"+s), []byte("value"+s))

// Broken Unpredictably
_, lastVersion, err = store.SaveVersion(nil)

// Works fine
// _, lastVersion, err = store.tree.SaveVersion()
ch <- lastVersion
enlight marked this conversation as resolved.
Show resolved Hide resolved
require.NoError(t, err)
fmt.Printf("%d\n", lastVersion)
require.Equal(t, i, lastVersion)
}
}()

for {
select {
case lv := <-ch:
fmt.Println("lv ", lv)
it, err := store.tree.GetImmutable(lv)
require.NoError(t, err)
require.NotNil(t, it)
}
}

}

func testFlush(t *testing.T) {
diskDb := getDiskDb(t, "testFlush")
store, err := NewIAVLStore(diskDb, 0, 0, flushInterval)
Expand Down