diff options
author | 2023-04-16 22:08:56 +0800 | |
---|---|---|
committer | 2023-04-16 16:08:56 +0200 | |
commit | 7db1d4f6e99f4ad01f514999b9baf816332d94af (patch) | |
tree | c62061e0b3e8f27246b3ae058e30ac9efca9ac0d /plugin/pkg/proxy/proxy_test.go | |
parent | 8e8231d627a690415da3df7b464cf45a00c0defa (diff) | |
download | coredns-7db1d4f6e99f4ad01f514999b9baf816332d94af.tar.gz coredns-7db1d4f6e99f4ad01f514999b9baf816332d94af.tar.zst coredns-7db1d4f6e99f4ad01f514999b9baf816332d94af.zip |
Prevent fail counter of a proxy overflows (#5990)
Signed-off-by: vanceli <vanceli@tencent.com>
Signed-off-by: Vance Li <vncl@YingyingM1.local>
Co-authored-by: vanceli <vanceli@tencent.com>
Diffstat (limited to 'plugin/pkg/proxy/proxy_test.go')
-rw-r--r-- | plugin/pkg/proxy/proxy_test.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/plugin/pkg/proxy/proxy_test.go b/plugin/pkg/proxy/proxy_test.go index 274e9679d..17125ea68 100644 --- a/plugin/pkg/proxy/proxy_test.go +++ b/plugin/pkg/proxy/proxy_test.go @@ -3,6 +3,7 @@ package proxy import ( "context" "crypto/tls" + "math" "testing" "time" @@ -97,3 +98,33 @@ func TestProtocolSelection(t *testing.T) { } } } + +func TestProxyIncrementFails(t *testing.T) { + var testCases = []struct { + name string + fails uint32 + expectFails uint32 + }{ + { + name: "increment fails counter overflows", + fails: math.MaxUint32, + expectFails: math.MaxUint32, + }, + { + name: "increment fails counter", + fails: 0, + expectFails: 1, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + p := NewProxy("bad_address", transport.DNS) + p.fails = tc.fails + p.incrementFails() + if p.fails != tc.expectFails { + t.Errorf("Expected fails to be %d, got %d", tc.expectFails, p.fails) + } + }) + } +} |