commit
096dcb90e6
|
@ -1,5 +1,13 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 0.3.2 (October 2, 2017)
|
||||||
|
|
||||||
|
BUG FIXES:
|
||||||
|
|
||||||
|
- [autofile] fix AutoFile.Sync() to open file if it's been closed
|
||||||
|
- [db] fix MemDb.Close() to not empty the database (ie. its just a noop)
|
||||||
|
|
||||||
|
|
||||||
## 0.3.1 (September 22, 2017)
|
## 0.3.1 (September 22, 2017)
|
||||||
|
|
||||||
BUG FIXES:
|
BUG FIXES:
|
||||||
|
|
|
@ -103,6 +103,11 @@ func (af *AutoFile) Sync() error {
|
||||||
af.mtx.Lock()
|
af.mtx.Lock()
|
||||||
defer af.mtx.Unlock()
|
defer af.mtx.Unlock()
|
||||||
|
|
||||||
|
if af.file == nil {
|
||||||
|
if err := af.openFile(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
return af.file.Sync()
|
return af.file.Sync()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,9 +52,11 @@ func (db *MemDB) DeleteSync(key []byte) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *MemDB) Close() {
|
func (db *MemDB) Close() {
|
||||||
db.mtx.Lock()
|
// Close is a noop since for an in-memory
|
||||||
defer db.mtx.Unlock()
|
// database, we don't have a destination
|
||||||
db = nil
|
// to flush contents to nor do we want
|
||||||
|
// any data loss on invoking Close()
|
||||||
|
// See the discussion in https://github.com/tendermint/tmlibs/pull/56
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *MemDB) Print() {
|
func (db *MemDB) Print() {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMemDbIterator(t *testing.T) {
|
func TestMemDbIterator(t *testing.T) {
|
||||||
|
@ -26,3 +27,22 @@ func TestMemDbIterator(t *testing.T) {
|
||||||
}
|
}
|
||||||
assert.Equal(t, i, len(db.db), "iterator didnt cover whole db")
|
assert.Equal(t, i, len(db.db), "iterator didnt cover whole db")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMemDBClose(t *testing.T) {
|
||||||
|
db := NewMemDB()
|
||||||
|
copyDB := func(orig map[string][]byte) map[string][]byte {
|
||||||
|
copy := make(map[string][]byte)
|
||||||
|
for k, v := range orig {
|
||||||
|
copy[k] = v
|
||||||
|
}
|
||||||
|
return copy
|
||||||
|
}
|
||||||
|
k, v := []byte("foo"), []byte("bar")
|
||||||
|
db.Set(k, v)
|
||||||
|
require.Equal(t, db.Get(k), v, "expecting a successful get")
|
||||||
|
copyBefore := copyDB(db.db)
|
||||||
|
db.Close()
|
||||||
|
require.Equal(t, db.Get(k), v, "Close is a noop, expecting a successful get")
|
||||||
|
copyAfter := copyDB(db.db)
|
||||||
|
require.Equal(t, copyBefore, copyAfter, "Close is a noop and shouldn't modify any internal data")
|
||||||
|
}
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
package version
|
package version
|
||||||
|
|
||||||
const Version = "0.3.1"
|
const Version = "0.3.2"
|
||||||
|
|
Loading…
Reference in New Issue