Skip to content

Commit

Permalink
chore: speeding up tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vlastahajek committed Apr 29, 2021
1 parent c7bb55d commit 97bd11c
Showing 1 changed file with 2 additions and 32 deletions.
34 changes: 2 additions & 32 deletions internal/write/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,37 +61,7 @@ func TestAddDefaultTags(t *testing.T) {
assert.Len(t, p.TagList(), 2)
}

func TestDefaultRetryDelay(t *testing.T) {
log.Log.SetLogLevel(log.DebugLevel)
hs := test.NewTestService(t, "http://localhost:8086")
opts := write.DefaultOptions()
ctx := context.Background()
srv := NewService("my-org", "my-bucket", hs, opts)
hs.SetReplyError(&http.Error{
StatusCode: 502,
})
b1 := NewBatch("", opts.RetryInterval())
err := srv.HandleWrite(ctx, b1)
assert.NotNil(t, err)
assert.Equal(t, uint(5000), b1.retryDelay)
assert.Equal(t, 1, srv.retryQueue.list.Len())
//wait retry delay + little more
<-time.After(time.Millisecond*time.Duration(b1.retryDelay) + time.Microsecond*5)
b2 := NewBatch("", opts.RetryInterval())
err = srv.HandleWrite(ctx, b2)
assert.NotNil(t, err)
assert.Equal(t, uint(25000), b1.retryDelay)
assert.Equal(t, 2, srv.retryQueue.list.Len())

<-time.After(time.Millisecond*time.Duration(b1.retryDelay) + time.Microsecond*5)
b3 := NewBatch("", opts.RetryInterval())
err = srv.HandleWrite(ctx, b3)
assert.NotNil(t, err)
assert.Equal(t, uint(125000), b1.retryDelay)
assert.Equal(t, 3, srv.retryQueue.list.Len())
}

func TestCustomRetryDelayWithFLush(t *testing.T) {
func TestRetryStrategy(t *testing.T) {
log.Log.SetLogLevel(log.DebugLevel)
hs := test.NewTestService(t, "http://localhost:8086")
opts := write.DefaultOptions().SetRetryInterval(1)
Expand Down Expand Up @@ -299,7 +269,7 @@ func TestWriteContextCancel(t *testing.T) {
var wg sync.WaitGroup
wg.Add(1)
go func() {
<-time.After(time.Second)
<-time.After(10 * time.Millisecond)
err = srv.HandleWrite(ctx, NewBatch(strings.Join(lines, "\n"), opts.RetryInterval()))
wg.Done()
}()
Expand Down

0 comments on commit 97bd11c

Please sign in to comment.