mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-07 18:21:20 +00:00
9c012cc0c8
* deprecate span map cache flag * fix tests * nishant feedback * fix startup * gaz * nishant feedback * gaz * Merge branch 'master' into deprecate_span_cache * fix img * Update slasher/usage_test.go * Merge refs/heads/master into deprecate_span_cache * Merge refs/heads/master into deprecate_span_cache * Merge refs/heads/master into deprecate_span_cache * Merge refs/heads/master into deprecate_span_cache * Merge refs/heads/master into deprecate_span_cache * Merge refs/heads/master into deprecate_span_cache * Merge refs/heads/master into deprecate_span_cache * Merge refs/heads/master into deprecate_span_cache * Merge refs/heads/master into deprecate_span_cache * Merge refs/heads/master into deprecate_span_cache * Merge refs/heads/master into deprecate_span_cache * fix up tests
58 lines
1.4 KiB
Go
58 lines
1.4 KiB
Go
package kv
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"fmt"
|
|
"math/big"
|
|
"os"
|
|
"path"
|
|
"testing"
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil"
|
|
"github.com/prysmaticlabs/prysm/slasher/db/iface"
|
|
"gopkg.in/urfave/cli.v2"
|
|
)
|
|
|
|
func setupDB(t testing.TB, ctx *cli.Context) *Store {
|
|
randPath, err := rand.Int(rand.Reader, big.NewInt(1000000))
|
|
if err != nil {
|
|
t.Fatalf("Could not generate random file path: %v", err)
|
|
}
|
|
p := path.Join(testutil.TempDir(), fmt.Sprintf("/%d", randPath))
|
|
if err := os.RemoveAll(p); err != nil {
|
|
t.Fatalf("Failed to remove directory: %v", err)
|
|
}
|
|
cfg := &Config{}
|
|
db, err := NewKVStore(p, cfg)
|
|
if err != nil {
|
|
t.Fatalf("Failed to instantiate DB: %v", err)
|
|
}
|
|
return db
|
|
}
|
|
|
|
func setupDBDiffCacheSize(t testing.TB, cacheSize int) *Store {
|
|
randPath, err := rand.Int(rand.Reader, big.NewInt(1000000))
|
|
if err != nil {
|
|
t.Fatalf("Could not generate random file path: %v", err)
|
|
}
|
|
p := path.Join(testutil.TempDir(), fmt.Sprintf("/%d", randPath))
|
|
if err := os.RemoveAll(p); err != nil {
|
|
t.Fatalf("Failed to remove directory: %v", err)
|
|
}
|
|
cfg := &Config{SpanCacheSize: cacheSize}
|
|
newDB, err := NewKVStore(p, cfg)
|
|
if err != nil {
|
|
t.Fatalf("Failed to instantiate DB: %v", err)
|
|
}
|
|
return newDB
|
|
}
|
|
|
|
func teardownDB(t testing.TB, db iface.Database) {
|
|
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)
|
|
}
|
|
}
|