You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.0 KiB

  1. package db
  2. import (
  3. "fmt"
  4. "testing"
  5. "github.com/stretchr/testify/require"
  6. "github.com/syndtr/goleveldb/leveldb/opt"
  7. cmn "github.com/tendermint/tendermint/libs/common"
  8. )
  9. func TestGoLevelDBNewGoLevelDB(t *testing.T) {
  10. name := fmt.Sprintf("test_%x", cmn.RandStr(12))
  11. defer cleanupDBDir("", name)
  12. // Test we can't open the db twice for writing
  13. wr1, err := NewGoLevelDB(name, "")
  14. require.Nil(t, err)
  15. _, err = NewGoLevelDB(name, "")
  16. require.NotNil(t, err)
  17. wr1.Close() // Close the db to release the lock
  18. // Test we can open the db twice for reading only
  19. ro1, err := NewGoLevelDBWithOpts(name, "", &opt.Options{ReadOnly: true})
  20. defer ro1.Close()
  21. require.Nil(t, err)
  22. ro2, err := NewGoLevelDBWithOpts(name, "", &opt.Options{ReadOnly: true})
  23. defer ro2.Close()
  24. require.Nil(t, err)
  25. }
  26. func BenchmarkGoLevelDBRandomReadsWrites(b *testing.B) {
  27. name := fmt.Sprintf("test_%x", cmn.RandStr(12))
  28. db, err := NewGoLevelDB(name, "")
  29. if err != nil {
  30. b.Fatal(err)
  31. }
  32. defer func() {
  33. db.Close()
  34. cleanupDBDir("", name)
  35. }()
  36. benchmarkRandomReadsWrites(b, db)
  37. }