mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-02 03:38:42 -07:00
[CHANGED] Reduce print for an account subs limit to every 2 sec
We could make it for all limits by having a map of error types instead of applying just to max subs. Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
This commit is contained in:
@@ -21,6 +21,7 @@ import (
|
||||
"io"
|
||||
"math"
|
||||
"net"
|
||||
"net/url"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"runtime"
|
||||
@@ -2517,3 +2518,58 @@ func TestClientLimits(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestClientClampMaxSubsErrReport(t *testing.T) {
|
||||
maxSubLimitReportThreshold = int64(100 * time.Millisecond)
|
||||
defer func() { maxSubLimitReportThreshold = defaultMaxSubLimitReportThreshold }()
|
||||
|
||||
o1 := DefaultOptions()
|
||||
o1.MaxSubs = 1
|
||||
o1.LeafNode.Host = "127.0.0.1"
|
||||
o1.LeafNode.Port = -1
|
||||
s1 := RunServer(o1)
|
||||
defer s1.Shutdown()
|
||||
|
||||
l := &captureErrorLogger{errCh: make(chan string, 10)}
|
||||
s1.SetLogger(l, false, false)
|
||||
|
||||
o2 := DefaultOptions()
|
||||
u, _ := url.Parse(fmt.Sprintf("nats://127.0.0.1:%d", o1.LeafNode.Port))
|
||||
o2.LeafNode.Remotes = []*RemoteLeafOpts{{URLs: []*url.URL{u}}}
|
||||
s2 := RunServer(o2)
|
||||
defer s2.Shutdown()
|
||||
|
||||
checkLeafNodeConnected(t, s1)
|
||||
checkLeafNodeConnected(t, s2)
|
||||
|
||||
nc := natsConnect(t, s2.ClientURL())
|
||||
natsSubSync(t, nc, "foo")
|
||||
natsSubSync(t, nc, "bar")
|
||||
|
||||
// Make sure we receive only 1
|
||||
check := func() {
|
||||
t.Helper()
|
||||
for i := 0; i < 2; i++ {
|
||||
select {
|
||||
case errStr := <-l.errCh:
|
||||
if i > 0 {
|
||||
t.Fatalf("Should not have logged a second time: %s", errStr)
|
||||
}
|
||||
if !strings.Contains(errStr, "maximum subscriptions") {
|
||||
t.Fatalf("Unexpected error: %s", errStr)
|
||||
}
|
||||
case <-time.After(300 * time.Millisecond):
|
||||
if i == 0 {
|
||||
t.Fatal("Error should have been logged")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
check()
|
||||
|
||||
// The above will have waited long enough to clear the report threshold.
|
||||
// So create two new subs and check again that we get only 1 report.
|
||||
natsSubSync(t, nc, "baz")
|
||||
natsSubSync(t, nc, "bat")
|
||||
check()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user