Fix intermittent test cases in cloud_pubsub (#5271)

This commit is contained in:
Daniel Nelson 2019-01-09 15:55:57 -08:00 committed by GitHub
parent 4b3580cceb
commit e20ba1e2b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 15 deletions

View File

@ -1,16 +1,17 @@
package cloud_pubsub
import (
"cloud.google.com/go/pubsub"
"context"
"fmt"
"sync"
"cloud.google.com/go/pubsub"
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/internal"
"github.com/influxdata/telegraf/plugins/outputs"
"github.com/influxdata/telegraf/plugins/serializers"
"golang.org/x/oauth2/google"
"google.golang.org/api/option"
"sync"
)
const sampleConfig = `

View File

@ -1,12 +1,13 @@
package cloud_pubsub
import (
"testing"
"cloud.google.com/go/pubsub"
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/plugins/parsers"
"github.com/influxdata/telegraf/testutil"
"github.com/stretchr/testify/assert"
"testing"
)
func TestPubSub_WriteSingle(t *testing.T) {

View File

@ -1,18 +1,20 @@
package cloud_pubsub
import (
"cloud.google.com/go/pubsub"
"context"
"errors"
"fmt"
"runtime"
"sync"
"testing"
"time"
"cloud.google.com/go/pubsub"
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/internal"
"github.com/influxdata/telegraf/plugins/parsers"
"github.com/influxdata/telegraf/plugins/serializers"
"google.golang.org/api/support/bundler"
"runtime"
"sync"
"testing"
)
const (
@ -138,7 +140,7 @@ func (t *stubTopic) SetPublishSettings(settings pubsub.PublishSettings) {
func (t *stubTopic) initBundler() *stubTopic {
t.bundler = bundler.NewBundler(&bundledMsg{}, t.sendBundle())
t.bundler.DelayThreshold = t.Settings.DelayThreshold
t.bundler.DelayThreshold = 10 * time.Second
t.bundler.BundleCountThreshold = t.Settings.CountThreshold
if t.bundler.BundleCountThreshold > pubsub.MaxPublishRequestCount {
t.bundler.BundleCountThreshold = pubsub.MaxPublishRequestCount
@ -159,14 +161,15 @@ func (t *stubTopic) sendBundle() func(items interface{}) {
for _, msg := range bundled {
r := msg.stubResult
for _, id := range r.metricIds {
t.published[id] = msg.Message
}
if r.sendError {
r.err <- errors.New(errMockFail)
} else {
r.done <- struct{}{}
}
for _, id := range r.metricIds {
t.published[id] = msg.Message
}
}
t.bundleCount++