aboutsummaryrefslogtreecommitdiff
path: root/plugin/forward/setup_test.go
diff options
context:
space:
mode:
authorGravatar Chris O'Haver <cohaver@infoblox.com> 2020-02-04 07:59:08 -0500
committerGravatar GitHub <noreply@github.com> 2020-02-04 13:59:08 +0100
commit22cd28a7987afc24161b110b550d3e62347d1626 (patch)
tree13431983c1374533989d34f9af2a4d981786a316 /plugin/forward/setup_test.go
parent8724a134c47b2d86fc20935201a4a8095ff290c4 (diff)
downloadcoredns-22cd28a7987afc24161b110b550d3e62347d1626.tar.gz
coredns-22cd28a7987afc24161b110b550d3e62347d1626.tar.zst
coredns-22cd28a7987afc24161b110b550d3e62347d1626.zip
plugins/forward: Add max_concurrent option (#3640)
* count and limit concurrent queries Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * add option Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * return servfail when limit exceeded Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * docs Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * docs Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * docs Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * review feedback Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * move atomic counter to beginning of struct Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * add comment for ErrLimitExceeded Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * rename option to max_concurrent Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * add metric Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * response REFUSED; incl max in error; add more docs Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * avoid err setup race Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * respond SERVFAIL; doc memory usage Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
Diffstat (limited to 'plugin/forward/setup_test.go')
-rw-r--r--plugin/forward/setup_test.go40
1 files changed, 39 insertions, 1 deletions
diff --git a/plugin/forward/setup_test.go b/plugin/forward/setup_test.go
index ae0c991d9..c2c2f6759 100644
--- a/plugin/forward/setup_test.go
+++ b/plugin/forward/setup_test.go
@@ -168,7 +168,45 @@ nameserver 10.10.255.253`), 0666); err != nil {
}
}
for _, p := range f.proxies {
- p.health.Check(p) // this should almost always err, we don't care it shoulnd't crash
+ p.health.Check(p) // this should almost always err, we don't care it shouldn't crash
+ }
+ }
+}
+
+func TestSetupMaxConcurrent(t *testing.T) {
+ tests := []struct {
+ input string
+ shouldErr bool
+ expectedVal int64
+ expectedErr string
+ }{
+ // positive
+ {"forward . 127.0.0.1 {\nmax_concurrent 1000\n}\n", false, 1000, ""},
+ // negative
+ {"forward . 127.0.0.1 {\nmax_concurrent many\n}\n", true, 0, "invalid"},
+ {"forward . 127.0.0.1 {\nmax_concurrent -4\n}\n", true, 0, "negative"},
+ }
+
+ for i, test := range tests {
+ c := caddy.NewTestController("dns", test.input)
+ f, err := parseForward(c)
+
+ if test.shouldErr && err == nil {
+ t.Errorf("Test %d: expected error but found %s for input %s", i, err, test.input)
+ }
+
+ if err != nil {
+ if !test.shouldErr {
+ t.Errorf("Test %d: expected no error but found one for input %s, got: %v", i, test.input, err)
+ }
+
+ if !strings.Contains(err.Error(), test.expectedErr) {
+ t.Errorf("Test %d: expected error to contain: %v, found error: %v, input: %s", i, test.expectedErr, err, test.input)
+ }
+ }
+
+ if !test.shouldErr && f.maxConcurrent != test.expectedVal {
+ t.Errorf("Test %d: expected: %d, got: %d", i, test.expectedVal, f.maxConcurrent)
}
}
}