storj/storage/postgreskv/alternateclient_test.go
paul cannon e2c0dd437a
offer PostgreSQL storage for pointerdb (#440)
..although it ought to work for other storage.KeyValueStore needs as
well. it's just optimized to work pretty well for a largish hierarchy of
paths.

This includes the addition of "long benchmarks" for KeyValueStore
testing. These will only be run when -test-bench-long is added to the
test flags. In these benchmarks, a large corpus of paths matching a
natural ("real-life") hierarchy is read from paths.data.gz (which you
can get from https://github.com/storj/path-test-corpus) and imported
into a particular KeyValueStore. Recursive and non-recursive queries are
run on it to detect performance problems that arise only at scale.

This also includes alternate implementation of the postgreskv client,
which works in a less-bizarre way for non-recursive queries, but suffers
from poor performance in tests such as the long benchmarks. Once this
alternate impl is committed to the tree, we can remove it again; I just
want it to be available for future reference.
2018-10-25 12:11:28 -05:00

74 lines
1.6 KiB
Go

// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information.
package postgreskv
import (
"flag"
"testing"
"go.uber.org/zap/zaptest"
"storj.io/storj/storage"
"storj.io/storj/storage/storelogger"
"storj.io/storj/storage/testsuite"
)
var (
doAltTests = flag.Bool("test-postgreskv-alt", false, "Run the KeyValueStore tests against the alternate PG implementation")
)
func newTestAlternatePostgres(t testing.TB) (store *AlternateClient, cleanup func()) {
if !*doAltTests {
t.Skip("alternate-implementation PG tests not enabled.")
}
if *testPostgres == "" {
t.Skipf("postgres flag missing, example:\n-postgres-test-db=%s", defaultPostgresConn)
}
pgdb, err := AltNew(*testPostgres)
if err != nil {
t.Fatalf("init: %v", err)
}
return pgdb, func() {
if err := pgdb.Close(); err != nil {
t.Fatalf("failed to close db: %v", err)
}
}
}
func TestSuiteAlt(t *testing.T) {
store, cleanup := newTestAlternatePostgres(t)
defer cleanup()
zap := zaptest.NewLogger(t)
testsuite.RunTests(t, storelogger.New(zap, store))
}
func BenchmarkSuiteAlt(b *testing.B) {
store, cleanup := newTestAlternatePostgres(b)
defer cleanup()
testsuite.RunBenchmarks(b, store)
}
type pgAltLongBenchmarkStore struct {
*AlternateClient
}
func (store *pgAltLongBenchmarkStore) BulkImport(iter storage.Iterator) error {
return bulkImport(store.pgConn, iter)
}
func (store *pgAltLongBenchmarkStore) BulkDelete() error {
return bulkDelete(store.pgConn)
}
func BenchmarkSuiteLongAlt(b *testing.B) {
store, cleanup := newTestAlternatePostgres(b)
defer cleanup()
testsuite.BenchmarkPathOperationsInLargeDb(b, &pgAltLongBenchmarkStore{store})
}