Config changes
- a source's interval must be greater than 0: a source is turned off with enabled, not with a zero interval, so JSCSourcesSource rejects an interval of 0 or less (its validate is promoted to each source's section); - max_message_size rejects -1: JSCServerWebSocket rejects a max_message_size of -1 (util.ByteSizeNoLimit), as a client could then exhaust the server's memory; - every setting documents what 0 or empty means (zero/none, no limit or a default).
This commit is contained in:
1 parent
49b824d5a2
commit
0b5fde9563
11 files changed
+116
-23
No files matched your search
@@ -527,3 +527,49 @@ func TestViperValue(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// max_message_size can't be -1 (no limit), directly or through the whole
|
||||
// configuration; 0 (the default) and explicit sizes are accepted.
|
||||
func TestWebSocketMaxMessageSizeNoLimit(t *testing.T) {
|
||||
var c JSCServerWebSocket
|
||||
if err := c.SetValue("max_message_size", "-1"); err == nil ||
|
||||
!strings.Contains(err.Error(), "can't be -1") {
|
||||
t.Errorf("SetValue(max_message_size, -1) = %v; want rejected", err)
|
||||
}
|
||||
if c.MaxMessageSize != 0 {
|
||||
t.Errorf("rejected size was stored: %v", c.MaxMessageSize)
|
||||
}
|
||||
for _, text := range []string{"0B", "64KiB"} {
|
||||
if err := c.SetValue("max_message_size", text); err != nil {
|
||||
t.Errorf("SetValue(max_message_size, %s): %v", text, err)
|
||||
}
|
||||
}
|
||||
conf := defaultConfig(t)
|
||||
if err := conf.SetValue("server.websocket.max_message_size", "-1"); err == nil {
|
||||
t.Error("JobSearchConfig.SetValue(server.websocket.max_message_size, -1) succeeded")
|
||||
}
|
||||
}
|
||||
|
||||
// A source's interval must be greater than 0, through the embedded section's
|
||||
// promoted validate; a source is turned off with enabled.
|
||||
func TestSourceIntervalMustBePositive(t *testing.T) {
|
||||
conf := defaultConfig(t)
|
||||
for _, key := range []string{
|
||||
"sources.find_a_tender.interval",
|
||||
"sources.fts_mock.interval",
|
||||
"sources.sleeper.interval",
|
||||
} {
|
||||
for _, value := range []string{"0s", "-1m"} {
|
||||
err := conf.SetValue(key, value)
|
||||
if err == nil || !strings.Contains(err.Error(), "greater than 0") {
|
||||
t.Errorf("SetValue(%s, %s) = %v; want rejected", key, value, err)
|
||||
}
|
||||
}
|
||||
if err := conf.SetValue(key, "1m"); err != nil {
|
||||
t.Errorf("SetValue(%s, 1m): %v", key, err)
|
||||
}
|
||||
}
|
||||
if conf.Sources.FindATender.Interval.Minutes() != 1 {
|
||||
t.Errorf("FindATender.Interval = %v; want 1m", conf.Sources.FindATender.Interval)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user