Skip to content
This repository has been archived by the owner on Mar 9, 2022. It is now read-only.

Commit

Permalink
Merge pull request #80 from mjs/disable-benchmark-logs
Browse files Browse the repository at this point in the history
Disable benchmark logs
  • Loading branch information
oplehto authored May 22, 2018
2 parents 633065d + 6c0f8f3 commit 84ccaa7
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 13 deletions.
13 changes: 13 additions & 0 deletions filter/rules_small_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"testing"
"time"

"github.com/jumptrading/influx-spout/spouttest"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -153,6 +154,9 @@ func TestMeasurementName(t *testing.T) {
var result int

func BenchmarkLineLookup(b *testing.B) {
spouttest.SuppressLogs()
defer spouttest.RestoreLogs()

rs := new(RuleSet)
rs.Append(CreateBasicRule("hello", ""))
line := []byte("hello world=42")
Expand All @@ -164,6 +168,9 @@ func BenchmarkLineLookup(b *testing.B) {
}

func BenchmarkLineLookupRegex(b *testing.B) {
spouttest.SuppressLogs()
defer spouttest.RestoreLogs()

rs := new(RuleSet)
rs.Append(CreateRegexRule("hello|abcde", ""))
line := []byte("hello world=42")
Expand All @@ -175,6 +182,9 @@ func BenchmarkLineLookupRegex(b *testing.B) {
}

func BenchmarkLineLookupNegativeRegex(b *testing.B) {
spouttest.SuppressLogs()
defer spouttest.RestoreLogs()

rs := new(RuleSet)
rs.Append(CreateNegativeRegexRule("hello|abcde", ""))
line := []byte("hello world=42")
Expand All @@ -186,6 +196,9 @@ func BenchmarkLineLookupNegativeRegex(b *testing.B) {
}

func BenchmarkProcessBatch(b *testing.B) {
spouttest.SuppressLogs()
defer spouttest.RestoreLogs()

// Run the Filter worker with a fake NATS connection.
rs := new(RuleSet)
rs.Append(CreateBasicRule("hello", "hello-out"))
Expand Down
35 changes: 24 additions & 11 deletions listener/listener_medium_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"fmt"
"net"
"net/http"
"os"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -61,16 +60,6 @@ func init() {
statsInterval = 500 * time.Millisecond
}

func TestMain(m *testing.M) {
os.Exit(runMain(m))
}

func runMain(m *testing.M) int {
s := spouttest.RunGnatsd(natsPort)
defer s.Shutdown()
return m.Run()
}

func testConfig() *config.Config {
return &config.Config{
Mode: "listener",
Expand All @@ -87,6 +76,9 @@ func testConfig() *config.Config {
}

func TestBatching(t *testing.T) {
s := spouttest.RunGnatsd(natsPort)
defer s.Shutdown()

conf := testConfig()
conf.BatchMessages = numLines // batch messages into one packet

Expand Down Expand Up @@ -115,6 +107,9 @@ func TestBatching(t *testing.T) {
}

func TestWhatComesAroundGoesAround(t *testing.T) {
s := spouttest.RunGnatsd(natsPort)
defer s.Shutdown()

listener := startListener(t, testConfig())
defer listener.Stop()

Expand All @@ -141,6 +136,9 @@ func TestWhatComesAroundGoesAround(t *testing.T) {
}

func TestBatchBufferFull(t *testing.T) {
s := spouttest.RunGnatsd(natsPort)
defer s.Shutdown()

conf := testConfig()
// Set batch size high so that the batch will only send due to the
// batch buffer filling up.
Expand Down Expand Up @@ -183,6 +181,9 @@ loop:
}

func TestHTTPListener(t *testing.T) {
s := spouttest.RunGnatsd(natsPort)
defer s.Shutdown()

conf := testConfig()
listener := startHTTPListener(t, conf)
defer listener.Stop()
Expand All @@ -209,6 +210,9 @@ func TestHTTPListener(t *testing.T) {
}

func TestHTTPListenerBigPOST(t *testing.T) {
s := spouttest.RunGnatsd(natsPort)
defer s.Shutdown()

conf := testConfig()
conf.ListenerBatchBytes = 1024
// Use a batch size > 1. Even though a single write will be made,
Expand Down Expand Up @@ -242,6 +246,9 @@ func TestHTTPListenerBigPOST(t *testing.T) {
}

func TestHTTPListenerConcurrency(t *testing.T) {
s := spouttest.RunGnatsd(natsPort)
defer s.Shutdown()

conf := testConfig()
listener := startHTTPListener(t, conf)
defer listener.Stop()
Expand Down Expand Up @@ -333,6 +340,12 @@ func TestHTTPListenerWithPrecision(t *testing.T) {
}

func BenchmarkListenerLatency(b *testing.B) {
spouttest.SuppressLogs()
defer spouttest.RestoreLogs()

s := spouttest.RunGnatsd(natsPort)
defer s.Shutdown()

listener := startListener(b, testConfig())
defer listener.Stop()

Expand Down
3 changes: 1 addition & 2 deletions perfcheck
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ capture_benchmarks() {
test_sizes=$1
output=$2

packages=`go list ./... | grep -v vendor`
go test -tags="$test_sizes" -run='^$' -bench=. $packages &>> $output
go test -tags="$test_sizes" -run='^$' -bench=. ./... &>> $output
if [[ $? -ne 0 ]]; then
cat $output
exit 1
Expand Down
17 changes: 17 additions & 0 deletions spouttest/logs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package spouttest

import (
"io/ioutil"
"log"
"os"
)

// SuppressLogs causes log output globally to be discarded.
func SuppressLogs() {
log.SetOutput(ioutil.Discard)
}

// RestoreLogs causes log output globally to be sent to stderr.
func RestoreLogs() {
log.SetOutput(os.Stderr)
}
3 changes: 3 additions & 0 deletions writer/writer_medium_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,9 @@ func TestNegativeRegexFilterRule(t *testing.T) {
}

func BenchmarkWriterLatency(b *testing.B) {
spouttest.SuppressLogs()
defer spouttest.RestoreLogs()

nc, closeNATS := runGnatsd(b)
defer closeNATS()

Expand Down

0 comments on commit 84ccaa7

Please sign in to comment.