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

Commit

Permalink
Suppress logs during benchmarks
Browse files Browse the repository at this point in the history
The logs are messing up the output meaning that perfcheck isn't able
to compare some benchmarks.
  • Loading branch information
mjs committed May 22, 2018
1 parent 5c8fc8a commit 3dcf3d7
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 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
6 changes: 6 additions & 0 deletions listener/listener_medium_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,12 @@ func TestHTTPListenerConcurrency(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
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 3dcf3d7

Please sign in to comment.