diff options
author | 2019-10-01 16:39:42 +0100 | |
---|---|---|
committer | 2019-10-01 16:39:42 +0100 | |
commit | 2d98d520b5c75d31e37dfe72a67b39707a56dc69 (patch) | |
tree | 2a7863ba64ec1e3ec6af7b4f8842b1d5b2f68ac5 /plugin/forward/persistent_test.go | |
parent | 7b69dfebb595fe08bc1fcf52234880da79d4e1aa (diff) | |
download | coredns-2d98d520b5c75d31e37dfe72a67b39707a56dc69.tar.gz coredns-2d98d520b5c75d31e37dfe72a67b39707a56dc69.tar.zst coredns-2d98d520b5c75d31e37dfe72a67b39707a56dc69.zip |
plugin/forward: make Yield not block (#3336)
* plugin/forward: may Yield not block
Yield may block when we're super busy with creating (and looking) for
connection. Set a small timeout on Yield, to skip putting the connection
back in the queue.
Use persistentConn troughout the socket handling code to be more
consistent.
Signed-off-by: Miek Gieben <miek@miek.nl>
Dont do
Signed-off-by: Miek Gieben <miek@miek.nl>
* Set used in Yield
This gives one central place where we update used in the persistConns
Signed-off-by: Miek Gieben <miek@miek.nl>
Diffstat (limited to 'plugin/forward/persistent_test.go')
-rw-r--r-- | plugin/forward/persistent_test.go | 52 |
1 files changed, 2 insertions, 50 deletions
diff --git a/plugin/forward/persistent_test.go b/plugin/forward/persistent_test.go index f1c906076..1fb239ca7 100644 --- a/plugin/forward/persistent_test.go +++ b/plugin/forward/persistent_test.go @@ -82,54 +82,6 @@ func TestCleanupByTimer(t *testing.T) { tr.Yield(c4) } -func TestPartialCleanup(t *testing.T) { - s := dnstest.NewServer(func(w dns.ResponseWriter, r *dns.Msg) { - ret := new(dns.Msg) - ret.SetReply(r) - w.WriteMsg(ret) - }) - defer s.Close() - - tr := newTransport(s.Addr) - tr.SetExpire(100 * time.Millisecond) - tr.Start() - defer tr.Stop() - - c1, _, _ := tr.Dial("udp") - c2, _, _ := tr.Dial("udp") - c3, _, _ := tr.Dial("udp") - c4, _, _ := tr.Dial("udp") - c5, _, _ := tr.Dial("udp") - - tr.Yield(c1) - time.Sleep(10 * time.Millisecond) - tr.Yield(c2) - time.Sleep(10 * time.Millisecond) - tr.Yield(c3) - time.Sleep(50 * time.Millisecond) - tr.Yield(c4) - time.Sleep(10 * time.Millisecond) - tr.Yield(c5) - time.Sleep(40 * time.Millisecond) - - c6, _, _ := tr.Dial("udp") - if c6 != c5 { - t.Errorf("Expected c6 == c5") - } - c7, _, _ := tr.Dial("udp") - if c7 != c4 { - t.Errorf("Expected c7 == c4") - } - c8, cached, _ := tr.Dial("udp") - if cached { - t.Error("Expected non-cached connection (c8)") - } - - tr.Yield(c6) - tr.Yield(c7) - tr.Yield(c8) -} - func TestCleanupAll(t *testing.T) { s := dnstest.NewServer(func(w dns.ResponseWriter, r *dns.Msg) { ret := new(dns.Msg) @@ -150,12 +102,12 @@ func TestCleanupAll(t *testing.T) { {c3, time.Now()}, } - if tr.len() != 3 { + if len(tr.conns["udp"]) != 3 { t.Error("Expected 3 connections") } tr.cleanup(true) - if tr.len() > 0 { + if len(tr.conns["udp"]) > 0 { t.Error("Expected no cached connections") } } |