Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: improve stability of BenchmarkPublisher (backport #11787) #12065

Merged
merged 1 commit into from
Nov 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions internal/publish/pub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package publish_test

import (
"bufio"
"compress/gzip"
"context"
"fmt"
"net/http"
Expand Down Expand Up @@ -102,16 +103,21 @@ func BenchmarkPublisher(b *testing.B) {
fmt.Fprintln(w, `{"version":{"number":"1.2.3"}}`)
})

var indexed int64
var indexed atomic.Int64
mux.HandleFunc("/_bulk", func(w http.ResponseWriter, r *http.Request) {
scanner := bufio.NewScanner(r.Body)
gzr, err := gzip.NewReader(r.Body)
assert.NoError(b, err)
defer gzr.Close()

scanner := bufio.NewScanner(gzr)
var n int64
for scanner.Scan() {
if scanner.Scan() {
for scanner.Scan() { // index
if scanner.Scan() { // actual event
n++
}
}
atomic.AddInt64(&indexed, n)
assert.NoError(b, scanner.Err())
indexed.Add(n)
})
srv := httptest.NewServer(mux)
defer srv.Close()
Expand Down Expand Up @@ -169,7 +175,7 @@ func BenchmarkPublisher(b *testing.B) {
assert.NoError(b, publisher.Stop(context.Background()))
assert.NoError(b, acker.Wait(context.Background()))
assert.NoError(b, pipeline.Close())
assert.Equal(b, int64(b.N), indexed)
assert.Equal(b, int64(b.N), indexed.Load())
}

func newBlockingPipeline(t testing.TB) (*pipeline.Pipeline, *mockClient) {
Expand Down