don't spam Travis + valid dnstap payload

This commit is contained in:
varyoo
2017-09-29 15:48:23 +02:00
parent 1e71d0e2c1
commit 830f637e06
2 changed files with 9 additions and 4 deletions

View File

@@ -3,6 +3,7 @@ package dnstapio
import ( import (
"fmt" "fmt"
"io" "io"
"os"
tap "github.com/dnstap/golang-dnstap" tap "github.com/dnstap/golang-dnstap"
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
@@ -10,6 +11,7 @@ import (
// DnstapIO wraps the dnstap I/O routine. // DnstapIO wraps the dnstap I/O routine.
type DnstapIO struct { type DnstapIO struct {
iolog io.Writer
writer io.WriteCloser writer io.WriteCloser
queue chan tap.Dnstap queue chan tap.Dnstap
stop chan bool stop chan bool
@@ -25,7 +27,7 @@ type Protocol interface {
// New dnstap I/O routine from Protocol. // New dnstap I/O routine from Protocol.
func New(w Protocol) *DnstapIO { func New(w Protocol) *DnstapIO {
dio := DnstapIO{} dio := DnstapIO{iolog: os.Stdout}
dio.writer = w dio.writer = w
dio.queue = make(chan tap.Dnstap, 10) dio.queue = make(chan tap.Dnstap, 10)
dio.stop = make(chan bool) dio.stop = make(chan bool)
@@ -38,7 +40,7 @@ func (dio *DnstapIO) Dnstap(payload tap.Dnstap) {
select { select {
case dio.queue <- payload: case dio.queue <- payload:
default: default:
fmt.Println("[WARN] Dnstap payload dropped.") fmt.Fprintln(dio.iolog, "[WARN] Dnstap payload dropped.")
} }
} }
@@ -50,7 +52,7 @@ func (dio *DnstapIO) serve() {
if err == nil { if err == nil {
dio.writer.Write(frame) dio.writer.Write(frame)
} else { } else {
fmt.Println("[ERROR] Invalid dnstap payload dropped.") fmt.Fprintf(dio.iolog, "[ERROR] Invalid dnstap payload dropped: %s\n", err)
} }
case <-dio.stop: case <-dio.stop:
close(dio.queue) close(dio.queue)

View File

@@ -2,6 +2,7 @@ package dnstapio
import ( import (
"bytes" "bytes"
"io/ioutil"
"sync" "sync"
"testing" "testing"
"time" "time"
@@ -26,6 +27,7 @@ func (b buf) Close() error {
func TestRace(t *testing.T) { func TestRace(t *testing.T) {
b := buf{&bytes.Buffer{}, 100 * time.Millisecond} b := buf{&bytes.Buffer{}, 100 * time.Millisecond}
dio := New(b) dio := New(b)
dio.iolog = ioutil.Discard // don't flood Travis
wg := &sync.WaitGroup{} wg := &sync.WaitGroup{}
wg.Add(10) wg.Add(10)
for i := 0; i < 10; i++ { for i := 0; i < 10; i++ {
@@ -38,7 +40,8 @@ func TestRace(t *testing.T) {
return return
default: default:
time.Sleep(50 * time.Millisecond) time.Sleep(50 * time.Millisecond)
dio.Dnstap(tap.Dnstap{}) t := tap.Dnstap_MESSAGE
dio.Dnstap(tap.Dnstap{Type: &t})
} }
} }
}() }()