plugin/forward: move Dial goroutine out (#1738)

Rework the TestProxyClose - close the proxy in the *same* goroutine
as where we started it. Close channels as long as we don't get dataraces
(this may need another fix).

Move the Dial goroutine out of the connManager - this simplifies things
*and* makes another goroutine go away and removes the need for connErr
channels - can now just be dns.Conn.

Also:

Revert "plugin/forward: gracefull stop (#1701)"
This reverts commit 135377bf77.

Revert "rework TestProxyClose (#1735)"
This reverts commit 9e8893a0b5.
This commit is contained in:
Miek Gieben 2018-04-26 09:34:58 +01:00 committed by GitHub
parent 4c7ae4ea95
commit 270da82995
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 117 deletions

View file

@ -2,9 +2,7 @@ package forward
import (
"context"
"runtime"
"testing"
"time"
"github.com/coredns/coredns/plugin/pkg/dnstest"
"github.com/coredns/coredns/plugin/test"
@ -28,50 +26,15 @@ func TestProxyClose(t *testing.T) {
ctx := context.TODO()
for i := 0; i < 100; i++ {
p := NewProxy(s.Addr, nil /* no TLS */)
p := NewProxy(s.Addr, nil)
p.start(hcDuration)
doneCnt := 0
doneCh := make(chan bool)
timeCh := time.After(10 * time.Second)
go func() {
p.connect(ctx, state, false, false)
doneCh <- true
}()
go func() {
p.connect(ctx, state, true, false)
doneCh <- true
}()
go func() {
p.close()
doneCh <- true
}()
go func() {
p.connect(ctx, state, false, false)
doneCh <- true
}()
go func() {
p.connect(ctx, state, true, false)
doneCh <- true
}()
go func() { p.connect(ctx, state, false, false) }()
go func() { p.connect(ctx, state, true, false) }()
go func() { p.connect(ctx, state, false, false) }()
go func() { p.connect(ctx, state, true, false) }()
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 {
t.Errorf("unexpected query in progress")
}
if p.state != stopped {
t.Errorf("unexpected proxy state, expected %d, got %d", stopped, p.state)
}
p.close()
}
}