Skip to content

Commit

Permalink
tests: fix races. (#10)
Browse files Browse the repository at this point in the history
* tests: fix races.

* remove useless ch recv.
  • Loading branch information
raulk committed May 3, 2020
2 parents 4bb2113 + 198dc89 commit 49845c3
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 8 deletions.
17 changes: 10 additions & 7 deletions runtime/influxdb_batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import (
)

func TestLengthBatching(t *testing.T) {
re, cleanup := RandomTestRunEnv(t)
runenv, cleanup := RandomTestRunEnv(t)
t.Cleanup(cleanup)
defer runenv.Close()

tc := &testClient{}
b := newBatcher(re, tc, 16, 24*time.Hour)
b := newBatcher(runenv, tc, 16, 24*time.Hour)

writePoints(t, b, 0, 36)

Expand All @@ -37,11 +38,12 @@ func TestLengthBatching(t *testing.T) {
}

func TestIntervalBatching(t *testing.T) {
re, cleanup := RandomTestRunEnv(t)
runenv, cleanup := RandomTestRunEnv(t)
t.Cleanup(cleanup)
defer runenv.Close()

tc := &testClient{}
b := newBatcher(re, tc, 1000, 500*time.Millisecond)
b := newBatcher(runenv, tc, 1000, 500*time.Millisecond)

writePoints(t, b, 0, 10)

Expand All @@ -62,8 +64,9 @@ func TestIntervalBatching(t *testing.T) {
}

func TestBatchFailure(t *testing.T) {
re, cleanup := RandomTestRunEnv(t)
runenv, cleanup := RandomTestRunEnv(t)
t.Cleanup(cleanup)
defer runenv.Close()

test := func(b *batcher) func(t *testing.T) {
tc := &testClient{}
Expand Down Expand Up @@ -107,12 +110,12 @@ func TestBatchFailure(t *testing.T) {
}
}

t.Run("batches_by_length", test(newBatcher(re, nil, 10, 24*time.Hour,
t.Run("batches_by_length", test(newBatcher(runenv, nil, 10, 24*time.Hour,
retry.Attempts(3),
retry.Delay(100*time.Millisecond),
)))

t.Run("batches_by_time", test(newBatcher(re, nil, 10, 100*time.Millisecond,
t.Run("batches_by_time", test(newBatcher(runenv, nil, 10, 100*time.Millisecond,
retry.Attempts(3),
retry.Delay(100*time.Millisecond),
)))
Expand Down
7 changes: 7 additions & 0 deletions sync/barrier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func TestBarrier(t *testing.T) {

runenv, cleanup := runtime.RandomTestRunEnv(t)
t.Cleanup(cleanup)
defer runenv.Close()

client, err := NewBoundClient(ctx, runenv)
if err != nil {
Expand Down Expand Up @@ -49,6 +50,7 @@ func TestBarrierBeyondTarget(t *testing.T) {

runenv, cleanup := runtime.RandomTestRunEnv(t)
t.Cleanup(cleanup)
defer runenv.Close()

client, err := NewBoundClient(ctx, runenv)
if err != nil {
Expand Down Expand Up @@ -77,6 +79,7 @@ func TestBarrierZero(t *testing.T) {

runenv, cleanup := runtime.RandomTestRunEnv(t)
t.Cleanup(cleanup)
defer runenv.Close()

client, err := NewBoundClient(ctx, runenv)
if err != nil {
Expand Down Expand Up @@ -104,6 +107,7 @@ func TestBarrierCancel(t *testing.T) {

runenv, cleanup := runtime.RandomTestRunEnv(t)
t.Cleanup(cleanup)
defer runenv.Close()

client, err := NewBoundClient(ctx, runenv)
if err != nil {
Expand Down Expand Up @@ -132,6 +136,7 @@ func TestBarrierDeadline(t *testing.T) {

runenv, cleanup := runtime.RandomTestRunEnv(t)
t.Cleanup(cleanup)
defer runenv.Close()

client, err := NewBoundClient(ctx, runenv)
if err != nil {
Expand Down Expand Up @@ -162,6 +167,7 @@ func TestSignalAndWait(t *testing.T) {

runenv, cleanup := runtime.RandomTestRunEnv(t)
t.Cleanup(cleanup)
defer runenv.Close()

client, err := NewBoundClient(ctx, runenv)
if err != nil {
Expand All @@ -185,6 +191,7 @@ func TestSignalAndWait(t *testing.T) {
func TestSignalAndWaitTimeout(t *testing.T) {
runenv, cleanup := runtime.RandomTestRunEnv(t)
t.Cleanup(cleanup)
defer runenv.Close()

client, err := NewBoundClient(context.Background(), runenv)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions sync/gc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func TestGC(t *testing.T) {

runenv, cleanup := runtime.RandomTestRunEnv(t)
t.Cleanup(cleanup)
defer runenv.Close()

client, err := NewBoundClient(ctx, runenv)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions sync/generic_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func TestGenericClientRunEnv(t *testing.T) {

runenv, cleanup := runtime.RandomTestRunEnv(t)
t.Cleanup(cleanup)
defer runenv.Close()

bclient, err := NewBoundClient(ctx, runenv)
if err != nil {
Expand Down
6 changes: 5 additions & 1 deletion sync/topic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func TestSubscribeAfterAllPublished(t *testing.T) {
)

t.Cleanup(cleanup)
defer runenv.Close()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down Expand Up @@ -73,6 +74,7 @@ func TestSubscribeFirstConcurrentWrites(t *testing.T) {
)

t.Cleanup(cleanup)
defer runenv.Close()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down Expand Up @@ -130,6 +132,7 @@ func TestSubscriptionConcurrentPublishersSubscribers(t *testing.T) {
)

t.Cleanup(cleanup)
defer runenv.Close()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down Expand Up @@ -178,8 +181,8 @@ func TestSubscriptionConcurrentPublishersSubscribers(t *testing.T) {

func TestSubscriptionValidation(t *testing.T) {
runenv, cleanup := runtime.RandomTestRunEnv(t)

t.Cleanup(cleanup)
defer runenv.Close()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down Expand Up @@ -221,6 +224,7 @@ func TestSequenceOnWrite(t *testing.T) {
)

t.Cleanup(cleanup)
defer runenv.Close()

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down

0 comments on commit 49845c3

Please sign in to comment.