Skip to content

Commit

Permalink
Pass store directly to journal tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmalloc committed Mar 19, 2024
1 parent f96a688 commit 4d8d8da
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 148 deletions.
8 changes: 2 additions & 6 deletions driver/aws/dynamojournal/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,15 @@ func TestStore(t *testing.T) {
client, table := setup(t)
journal.RunTests(
t,
func(t *testing.T) journal.BinaryStore {
return NewBinaryStore(client, table)
},
NewBinaryStore(client, table),
)
}

func BenchmarkStore(b *testing.B) {
client, table := setup(b)
journal.RunBenchmarks(
b,
func(b *testing.B) journal.BinaryStore {
return NewBinaryStore(client, table)
},
NewBinaryStore(client, table),
)
}

Expand Down
8 changes: 2 additions & 6 deletions driver/memory/memoryjournal/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,13 @@ import (
func TestStore(t *testing.T) {
journal.RunTests(
t,
func(t *testing.T) journal.BinaryStore {
return &BinaryStore{}
},
&BinaryStore{},
)
}

func BenchmarkStore(b *testing.B) {
journal.RunBenchmarks(
b,
func(b *testing.B) journal.BinaryStore {
return &BinaryStore{}
},
&BinaryStore{},
)
}
12 changes: 4 additions & 8 deletions driver/sql/postgres/pgjournal/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ func TestStore(t *testing.T) {
db := setup(t)
journal.RunTests(
t,
func(t *testing.T) journal.BinaryStore {
return &BinaryStore{
DB: db,
}
&BinaryStore{
DB: db,
},
)
}
Expand All @@ -27,10 +25,8 @@ func BenchmarkStore(b *testing.B) {
db := setup(b)
journal.RunBenchmarks(
b,
func(b *testing.B) journal.BinaryStore {
return &BinaryStore{
DB: db,
}
&BinaryStore{
DB: db,
},
)
}
Expand Down
40 changes: 15 additions & 25 deletions journal/benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
// RunBenchmarks runs benchmarks against a [BinaryStore] implementation.
func RunBenchmarks(
b *testing.B,
newStore func(b *testing.B) BinaryStore,
store BinaryStore,
) {
b.Run("Store", func(b *testing.B) {
b.Run("Open", func(b *testing.B) {
Expand All @@ -21,7 +21,7 @@ func RunBenchmarks(

benchmarkStore(
b,
newStore,
store,
// SETUP
func(ctx context.Context, s BinaryStore) error {
name = uniqueName()
Expand Down Expand Up @@ -51,7 +51,7 @@ func RunBenchmarks(

benchmarkStore(
b,
newStore,
store,
// SETUP
nil,
// BEFORE EACH
Expand All @@ -77,7 +77,7 @@ func RunBenchmarks(
b.Run("empty journal", func(b *testing.B) {
benchmarkJournal(
b,
newStore,
store,
// SETUP
nil,
// BEFORE EACH
Expand All @@ -95,7 +95,7 @@ func RunBenchmarks(
b.Run("non-empty journal", func(b *testing.B) {
benchmarkJournal(
b,
newStore,
store,
// SETUP
func(ctx context.Context, s BinaryStore, j BinaryJournal) error {
for pos := Position(0); pos < 10000; pos++ {
Expand All @@ -121,7 +121,7 @@ func RunBenchmarks(
b.Run("truncated journal", func(b *testing.B) {
benchmarkJournal(
b,
newStore,
store,
// SETUP
func(ctx context.Context, s BinaryStore, j BinaryJournal) error {
for pos := Position(0); pos < 10000; pos++ {
Expand Down Expand Up @@ -152,7 +152,7 @@ func RunBenchmarks(

benchmarkJournal(
b,
newStore,
store,
// SETUP
nil,
// BEFORE EACH
Expand All @@ -178,7 +178,7 @@ func RunBenchmarks(

benchmarkJournal(
b,
newStore,
store,
// SETUP
func(ctx context.Context, _ BinaryStore, j BinaryJournal) error {
for pos := Position(0); pos < 10000; pos++ {
Expand Down Expand Up @@ -213,7 +213,7 @@ func RunBenchmarks(

benchmarkJournal(
b,
newStore,
store,
// SETUP
nil,
// BEFORE EACH
Expand All @@ -233,7 +233,7 @@ func RunBenchmarks(
b.Run("Range (3k records)", func(b *testing.B) {
benchmarkJournal(
b,
newStore,
store,
// SETUP
func(ctx context.Context, _ BinaryStore, j BinaryJournal) error {
rec := []byte("<record>")
Expand Down Expand Up @@ -266,7 +266,7 @@ func RunBenchmarks(

benchmarkJournal(
b,
newStore,
store,
// SETUP
func(ctx context.Context, _ BinaryStore, j BinaryJournal) error {
rec := []byte("<record>")
Expand All @@ -293,22 +293,17 @@ func RunBenchmarks(

func benchmarkStore[T any](
b *testing.B,
newStore func(b *testing.B) BinaryStore,
store BinaryStore,
setup func(context.Context, BinaryStore) error,
before func(context.Context, BinaryStore) error,
fn func(context.Context, BinaryStore) (T, error),
after func(T) error,
) {
var (
store BinaryStore
result T
)
var result T

benchmark.Run(
b,
func(ctx context.Context) error {
store = newStore(b)

if setup != nil {
return setup(ctx, store)
}
Expand Down Expand Up @@ -337,22 +332,17 @@ func benchmarkStore[T any](

func benchmarkJournal(
b *testing.B,
newStore func(b *testing.B) BinaryStore,
store BinaryStore,
setup func(context.Context, BinaryStore, BinaryJournal) error,
before func(context.Context, BinaryJournal) error,
fn func(context.Context, BinaryJournal) error,
after func() error,
) {
var (
store BinaryStore
journ BinaryJournal
)
var journ BinaryJournal

benchmark.Run(
b,
func(ctx context.Context) error {
store = newStore(b)

var err error
journ, err = store.Open(ctx, uniqueName())
if err != nil {
Expand Down
14 changes: 6 additions & 8 deletions journal/telemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ import (
func TestWithTelemetry(t *testing.T) {
RunTests(
t,
func(t *testing.T) BinaryStore {
return WithTelemetry(
&memoryjournal.BinaryStore{},
nooptrace.NewTracerProvider(),
noopmetric.NewMeterProvider(),
spruce.NewLogger(t),
)
},
WithTelemetry(
&memoryjournal.BinaryStore{},
nooptrace.NewTracerProvider(),
noopmetric.NewMeterProvider(),
spruce.NewLogger(t),
),
)
}
Loading

0 comments on commit 4d8d8da

Please sign in to comment.