mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 02:44:59 +00:00
make sure more tests and benchmarks can have their temp dir set by flag
This is to allow the directory to be set to where a particular disk is mounted during benchmarking.
This commit is contained in:
parent
1c470e4c10
commit
fe7b926773
11 changed files with 49 additions and 18 deletions
|
|
@ -83,7 +83,7 @@ func TestFragCombos(t *testing.T) {
|
|||
|
||||
// newIndexWithTempPath returns a new instance of Index.
|
||||
func newIndexWithTempPath(name string) *Index {
|
||||
path, err := ioutil.TempDir("", "pilosa-index-")
|
||||
path, err := ioutil.TempDir(*TempDir, "pilosa-index-")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ func TestExecutor_TranslateGroupByCall(t *testing.T) {
|
|||
e := &executor{
|
||||
Holder: NewHolder(),
|
||||
}
|
||||
e.Holder.Path, _ = ioutil.TempDir("", "")
|
||||
e.Holder.Path, _ = ioutil.TempDir(*TempDir, "")
|
||||
err := e.Holder.Open()
|
||||
if err != nil {
|
||||
t.Fatalf("opening holder: %v", err)
|
||||
|
|
|
|||
|
|
@ -16,7 +16,9 @@ package pilosa_test
|
|||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"math/rand"
|
||||
"reflect"
|
||||
"strconv"
|
||||
|
|
@ -33,6 +35,20 @@ import (
|
|||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var (
|
||||
TempDir *string
|
||||
)
|
||||
|
||||
func init() {
|
||||
tdflag := flag.Lookup("temp-dir")
|
||||
if tdflag == nil {
|
||||
TempDir = flag.String("temp-dir", "", "Directory in which to place temporary data (e.g. for benchmarking). Useful if you are trying to benchmark different storage configurations.")
|
||||
} else {
|
||||
s := tdflag.Value.String()
|
||||
TempDir = &s
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure a row query can be executed.
|
||||
func TestExecutor_Execute_Row(t *testing.T) {
|
||||
t.Run("RowIDColumnID", func(t *testing.T) {
|
||||
|
|
@ -2987,7 +3003,16 @@ func TestExecutor_Execute_SetRow(t *testing.T) {
|
|||
}
|
||||
|
||||
func benchmarkExistence(nn bool, b *testing.B) {
|
||||
c := test.MustRunCluster(b, 1)
|
||||
c := test.MustNewCluster(b, 1)
|
||||
var err error
|
||||
c[0].Config.DataDir, err = ioutil.TempDir(*TempDir, "benchmarkExistence")
|
||||
if err != nil {
|
||||
b.Fatalf("getting temp dir: %v", err)
|
||||
}
|
||||
err = c.Start()
|
||||
if err != nil {
|
||||
b.Fatalf("starting cluster: %v", err)
|
||||
}
|
||||
defer c.Close()
|
||||
hldr := test.Holder{Holder: c[0].Server.Holder()}
|
||||
|
||||
|
|
@ -3587,7 +3612,16 @@ func TestExecutor_Execute_GroupBy(t *testing.T) {
|
|||
}
|
||||
|
||||
func BenchmarkGroupBy(b *testing.B) {
|
||||
c := test.MustRunCluster(b, 1)
|
||||
c := test.MustNewCluster(b, 1)
|
||||
var err error
|
||||
c[0].Config.DataDir, err = ioutil.TempDir(*TempDir, "benchmarkGroupBy")
|
||||
if err != nil {
|
||||
b.Fatalf("getting temp dir: %v", err)
|
||||
}
|
||||
err = c.Start()
|
||||
if err != nil {
|
||||
b.Fatalf("starting cluster: %v", err)
|
||||
}
|
||||
defer c.Close()
|
||||
c.CreateField(b, "i", pilosa.IndexOptions{}, "a")
|
||||
c.CreateField(b, "i", pilosa.IndexOptions{}, "b")
|
||||
|
|
|
|||
|
|
@ -192,7 +192,7 @@ type TestField struct {
|
|||
|
||||
// NewTestField returns a new instance of TestField d/0.
|
||||
func NewTestField(opts FieldOption) *TestField {
|
||||
path, err := ioutil.TempDir("", "pilosa-field-")
|
||||
path, err := ioutil.TempDir(*TempDir, "pilosa-field-")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,12 +39,9 @@ var (
|
|||
// In order to generate the sample fragment file,
|
||||
// run an import and copy PILOSA_DATA_DIR/INDEX_NAME/FRAME_NAME/0 to testdata/sample_view
|
||||
FragmentPath = flag.String("fragment", "testdata/sample_view/0", "fragment path")
|
||||
TempDir = ""
|
||||
)
|
||||
|
||||
func init() { // nolint: gochecknoinits
|
||||
flag.StringVar(&TempDir, "temp-dir", "", "Directory in which to place temporary data (e.g. for benchmarking). Useful if you are trying to benchmark different storage configurations.")
|
||||
}
|
||||
TempDir = flag.String("temp-dir", "", "Directory in which to place temporary data (e.g. for benchmarking). Useful if you are trying to benchmark different storage configurations.")
|
||||
)
|
||||
|
||||
// Ensure a fragment can set a bit and retrieve it.
|
||||
func TestFragment_SetBit(t *testing.T) {
|
||||
|
|
@ -2069,7 +2066,7 @@ func BenchmarkFileWrite(b *testing.B) {
|
|||
b.Run(fmt.Sprintf("Rows%d", numRows), func(b *testing.B) {
|
||||
b.StopTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
f, err := ioutil.TempFile(TempDir, "")
|
||||
f, err := ioutil.TempFile(*TempDir, "")
|
||||
if err != nil {
|
||||
b.Fatalf("getting temp file: %v", err)
|
||||
}
|
||||
|
|
@ -2125,7 +2122,7 @@ func (f *fragment) CleanKeep(t testing.TB) {
|
|||
|
||||
// mustOpenFragment returns a new instance of Fragment with a temporary path.
|
||||
func mustOpenFragment(index, field, view string, shard uint64, cacheType string) *fragment {
|
||||
file, err := ioutil.TempFile(TempDir, "pilosa-fragment-")
|
||||
file, err := ioutil.TempFile(*TempDir, "pilosa-fragment-")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ func (h *tHolder) Reopen() error {
|
|||
}
|
||||
|
||||
func newHolder() *tHolder {
|
||||
path, err := ioutil.TempDir("", "pilosa-")
|
||||
path, err := ioutil.TempDir(*TempDir, "pilosa-")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ import (
|
|||
|
||||
// mustOpenIndex returns a new, opened index at a temporary path. Panic on error.
|
||||
func mustOpenIndex(opt IndexOptions) *Index {
|
||||
path, err := ioutil.TempDir("", "pilosa-index-")
|
||||
path, err := ioutil.TempDir(*TempDir, "pilosa-index-")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ func TestCountOpenFiles(t *testing.T) {
|
|||
|
||||
func TestMonitorAntiEntropyZero(t *testing.T) {
|
||||
|
||||
td, err := ioutil.TempDir("", "")
|
||||
td, err := ioutil.TempDir(*TempDir, "")
|
||||
if err != nil {
|
||||
t.Fatalf("getting temp dir: %v", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -803,7 +803,7 @@ type TranslateFile struct {
|
|||
}
|
||||
|
||||
func NewTranslateFile() *TranslateFile {
|
||||
f, err := ioutil.TempFile("", "")
|
||||
f, err := ioutil.TempFile(*TempDir, "")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -212,7 +212,7 @@ func (t *ClusterCluster) addCluster(i int, saveTopology bool) (*cluster, error)
|
|||
t.common.Nodes = append(t.common.Nodes, node)
|
||||
|
||||
// create node-specific temp directory
|
||||
path, err := ioutil.TempDir("", fmt.Sprintf("pilosa-cluster-node-%d-", i))
|
||||
path, err := ioutil.TempDir(*TempDir, fmt.Sprintf("pilosa-cluster-node-%d-", i))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ import (
|
|||
|
||||
// mustOpenView returns a new instance of View with a temporary path.
|
||||
func mustOpenView(index, field, name string) *view {
|
||||
path, err := ioutil.TempDir("", "pilosa-view-")
|
||||
path, err := ioutil.TempDir(*TempDir, "pilosa-view-")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue