prysm-pulse/beacon-chain/db/db_test.go
Ivan Martinez 700264b3c7 Add caching to beacon state DB (#1775)
* Initial addition to cache beacon state

* Add benchmark to tests

* Fix benchmarks

* Fix benchmarks

* Fix caching to requests

* Update to master

* Remove b.N assignments

* Init cache on state init
2019-03-12 15:30:10 -04:00

40 lines
935 B
Go

package db
import (
"crypto/rand"
"fmt"
"math/big"
"os"
"path"
"testing"
"github.com/prysmaticlabs/prysm/shared/testutil"
)
// setupDB instantiates and returns a BeaconDB instance.
func setupDB(t testing.TB) *BeaconDB {
randPath, err := rand.Int(rand.Reader, big.NewInt(1000000))
if err != nil {
t.Fatalf("Could not generate random file path: %v", err)
}
path := path.Join(testutil.TempDir(), fmt.Sprintf("/%d", randPath))
if err := os.RemoveAll(path); err != nil {
t.Fatalf("Failed to remove directory: %v", err)
}
db, err := NewDB(path)
if err != nil {
t.Fatalf("Failed to instantiate DB: %v", err)
}
return db
}
// teardownDB cleans up a test BeaconDB instance.
func teardownDB(t testing.TB, db *BeaconDB) {
if err := db.Close(); err != nil {
t.Fatalf("Failed to close database: %v", err)
}
if err := os.RemoveAll(db.DatabasePath); err != nil {
t.Fatalf("Failed to remove directory: %v", err)
}
}