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

View File

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