rework TestProxyClose (#1735)

This commit is contained in:
Ruslan Drozhdzh 2018-04-25 21:15:49 +03:00 committed by Miek Gieben
parent 5c3e436d71
commit 9e8893a0b5

View file

@ -2,8 +2,9 @@ package forward
import ( import (
"context" "context"
"sync" "runtime"
"testing" "testing"
"time"
"github.com/coredns/coredns/plugin/pkg/dnstest" "github.com/coredns/coredns/plugin/pkg/dnstest"
"github.com/coredns/coredns/plugin/test" "github.com/coredns/coredns/plugin/test"
@ -30,30 +31,41 @@ func TestProxyClose(t *testing.T) {
p := NewProxy(s.Addr, nil /* no TLS */) p := NewProxy(s.Addr, nil /* no TLS */)
p.start(hcDuration) p.start(hcDuration)
var wg sync.WaitGroup doneCnt := 0
wg.Add(5) doneCh := make(chan bool)
timeCh := time.After(10 * time.Second)
go func() { go func() {
p.connect(ctx, state, false, false) p.connect(ctx, state, false, false)
wg.Done() doneCh <- true
}() }()
go func() { go func() {
p.connect(ctx, state, true, false) p.connect(ctx, state, true, false)
wg.Done() doneCh <- true
}() }()
go func() { go func() {
p.close() p.close()
wg.Done() doneCh <- true
}() }()
go func() { go func() {
p.connect(ctx, state, false, false) p.connect(ctx, state, false, false)
wg.Done() doneCh <- true
}() }()
go func() { go func() {
p.connect(ctx, state, true, false) p.connect(ctx, state, true, false)
wg.Done() doneCh <- true
}() }()
wg.Wait()
for doneCnt < 5 {
select {
case <-doneCh:
doneCnt++
case <-timeCh:
t.Error("TestProxyClose is running too long, dumping goroutines:")
buf := make([]byte, 100000)
stackSize := runtime.Stack(buf, true)
t.Fatal(string(buf[:stackSize]))
}
}
if p.inProgress != 0 { if p.inProgress != 0 {
t.Errorf("unexpected query in progress") t.Errorf("unexpected query in progress")
} }