Fix intermittent test cases in cloud_pubsub (#5271)
This commit is contained in:
parent
4b3580cceb
commit
e20ba1e2b6
|
@ -1,16 +1,17 @@
|
||||||
package cloud_pubsub
|
package cloud_pubsub
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"cloud.google.com/go/pubsub"
|
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"cloud.google.com/go/pubsub"
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
"github.com/influxdata/telegraf/internal"
|
"github.com/influxdata/telegraf/internal"
|
||||||
"github.com/influxdata/telegraf/plugins/outputs"
|
"github.com/influxdata/telegraf/plugins/outputs"
|
||||||
"github.com/influxdata/telegraf/plugins/serializers"
|
"github.com/influxdata/telegraf/plugins/serializers"
|
||||||
"golang.org/x/oauth2/google"
|
"golang.org/x/oauth2/google"
|
||||||
"google.golang.org/api/option"
|
"google.golang.org/api/option"
|
||||||
"sync"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const sampleConfig = `
|
const sampleConfig = `
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
package cloud_pubsub
|
package cloud_pubsub
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
"cloud.google.com/go/pubsub"
|
"cloud.google.com/go/pubsub"
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
"github.com/influxdata/telegraf/plugins/parsers"
|
"github.com/influxdata/telegraf/plugins/parsers"
|
||||||
"github.com/influxdata/telegraf/testutil"
|
"github.com/influxdata/telegraf/testutil"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPubSub_WriteSingle(t *testing.T) {
|
func TestPubSub_WriteSingle(t *testing.T) {
|
||||||
|
|
|
@ -1,18 +1,20 @@
|
||||||
package cloud_pubsub
|
package cloud_pubsub
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"cloud.google.com/go/pubsub"
|
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"runtime"
|
||||||
|
"sync"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"cloud.google.com/go/pubsub"
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
"github.com/influxdata/telegraf/internal"
|
"github.com/influxdata/telegraf/internal"
|
||||||
"github.com/influxdata/telegraf/plugins/parsers"
|
"github.com/influxdata/telegraf/plugins/parsers"
|
||||||
"github.com/influxdata/telegraf/plugins/serializers"
|
"github.com/influxdata/telegraf/plugins/serializers"
|
||||||
"google.golang.org/api/support/bundler"
|
"google.golang.org/api/support/bundler"
|
||||||
"runtime"
|
|
||||||
"sync"
|
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -138,7 +140,7 @@ func (t *stubTopic) SetPublishSettings(settings pubsub.PublishSettings) {
|
||||||
|
|
||||||
func (t *stubTopic) initBundler() *stubTopic {
|
func (t *stubTopic) initBundler() *stubTopic {
|
||||||
t.bundler = bundler.NewBundler(&bundledMsg{}, t.sendBundle())
|
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
|
t.bundler.BundleCountThreshold = t.Settings.CountThreshold
|
||||||
if t.bundler.BundleCountThreshold > pubsub.MaxPublishRequestCount {
|
if t.bundler.BundleCountThreshold > pubsub.MaxPublishRequestCount {
|
||||||
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 {
|
for _, msg := range bundled {
|
||||||
r := msg.stubResult
|
r := msg.stubResult
|
||||||
|
for _, id := range r.metricIds {
|
||||||
|
t.published[id] = msg.Message
|
||||||
|
}
|
||||||
|
|
||||||
if r.sendError {
|
if r.sendError {
|
||||||
r.err <- errors.New(errMockFail)
|
r.err <- errors.New(errMockFail)
|
||||||
} else {
|
} else {
|
||||||
r.done <- struct{}{}
|
r.done <- struct{}{}
|
||||||
}
|
}
|
||||||
for _, id := range r.metricIds {
|
|
||||||
t.published[id] = msg.Message
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
t.bundleCount++
|
t.bundleCount++
|
||||||
|
|
Loading…
Reference in New Issue