forked from mtusi2026/mtusi2026lab6
40 lines
1.2 KiB
Go
40 lines
1.2 KiB
Go
package config
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestRejectsConfigurationOutsideResourceBudget(t *testing.T) {
|
|
for _, tc := range []struct{ key, value string }{{"MAX_INFLIGHT", "0"}, {"MAX_INFLIGHT", "5"}, {"MAX_QUEUE", "-1"}, {"MAX_QUEUE", "129"}, {"QUEUE_TIMEOUT", "0s"}, {"QUEUE_TIMEOUT", "3s"}, {"MAX_BODY_BYTES", "0"}, {"MAX_BODY_BYTES", "65537"}, {"PG_MAX_CONNS", "0"}, {"PG_MAX_CONNS", "65"}, {"SESSION_TTL_SECONDS", "0"}, {"SESSION_TTL_SECONDS", "86401"}} {
|
|
t.Run(tc.key+tc.value, func(t *testing.T) {
|
|
t.Setenv(tc.key, tc.value)
|
|
if _, e := Load(); e == nil {
|
|
t.Fatal("accepted configuration beyond tested bounds")
|
|
}
|
|
})
|
|
}
|
|
}
|
|
func TestPoolSizeIsConfigurableWithinBounds(t *testing.T) {
|
|
t.Setenv("PG_MAX_CONNS", "1")
|
|
cfg, e := Load()
|
|
if e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
if cfg.MaxConns != 1 {
|
|
t.Fatal("configured pool size ignored")
|
|
}
|
|
}
|
|
|
|
func TestTelemetryDrainLeavesRoomForExporterWithinStopDeadline(t *testing.T) {
|
|
t.Setenv("SHUTDOWN_TIMEOUT", "5s")
|
|
if _, e := Load(); e == nil {
|
|
t.Fatal("HTTP drain leaves no safe reserve for exporter/pool teardown before8s stop")
|
|
}
|
|
t.Setenv("SHUTDOWN_TIMEOUT", "3s")
|
|
cfg, e := Load()
|
|
if e != nil || cfg.ShutdownTimeout != 3*time.Second {
|
|
t.Fatal("bounded drain rejected")
|
|
}
|
|
}
|