Skip to content

Commit

Permalink
test(batch): Fix data races in tests
Browse files Browse the repository at this point in the history
Fixes: 9b984b0
  • Loading branch information
mgaffney committed Nov 19, 2024
1 parent 963e276 commit e086fd3
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions internal/scheduler/batch/batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"errors"
"fmt"
"sync"
"testing"
"time"

Expand Down Expand Up @@ -300,18 +301,25 @@ type recorder struct {
execBatchSize int
storeBatchSize int
status scheduler.JobStatus
mu sync.Mutex
}

func (r *recorder) setup(c *Config) {
r.mu.Lock()
defer r.mu.Unlock()
c.Store = r.Store
}

func (r *recorder) Store(ctx context.Context, batchSize int) error {
r.mu.Lock()
defer r.mu.Unlock()
r.storeBatchSize = batchSize
return nil
}

func (r *recorder) Exec(ctx context.Context, batchSize int) (int, error) {
r.mu.Lock()
defer r.mu.Unlock()
r.execBatchSize = batchSize
return 0, nil
}
Expand All @@ -320,6 +328,7 @@ type testRun struct {
ret func(context.Context, int, *Config) (int, error)
chk func(*testing.T, *recorder)
rec *recorder
mu sync.Mutex
}

func (tr *testRun) validate(t *testing.T) {
Expand All @@ -329,6 +338,8 @@ func (tr *testRun) validate(t *testing.T) {
}

func (tr *testRun) recorder(cf *Config) *recorder {
tr.mu.Lock()
defer tr.mu.Unlock()
if tr.rec == nil {
tr.rec = &recorder{}
tr.rec.setup(cf)
Expand Down

0 comments on commit e086fd3

Please sign in to comment.