Skip to content

Commit

Permalink
Fix graylog test race
Browse files Browse the repository at this point in the history
  • Loading branch information
sparrc committed Jun 1, 2016
1 parent fb5f403 commit c842724
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions plugins/outputs/graylog/graylog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ import (

func TestWrite(t *testing.T) {
var wg sync.WaitGroup
var wg2 sync.WaitGroup
wg.Add(1)
go UDPServer(t, &wg)
wg2.Add(1)
go UDPServer(t, &wg, &wg2)
wg2.Wait()

i := Graylog{
Servers: []string{"127.0.0.1:12201"},
Expand All @@ -33,12 +36,13 @@ func TestWrite(t *testing.T) {

type GelfObject map[string]interface{}

func UDPServer(t *testing.T, wg *sync.WaitGroup) {
func UDPServer(t *testing.T, wg *sync.WaitGroup, wg2 *sync.WaitGroup) {
serverAddr, _ := net.ResolveUDPAddr("udp", "127.0.0.1:12201")
udpServer, _ := net.ListenUDP("udp", serverAddr)
defer wg.Done()

bufR := make([]byte, 1024)
wg2.Done()
n, _, _ := udpServer.ReadFromUDP(bufR)

b := bytes.NewReader(bufR[0:n])
Expand Down

0 comments on commit c842724

Please sign in to comment.