server was sized for a campfire, not a fleet. 25 db connections, every agent report flinging goroutines into the void, the syncer plodding one repo at a time while clutching a lock nobody needed. loosened the choke points: - db pool 25 -> 100 + connection lifetime, all env-tunable - bounded pool for the report-path fire-and-forget work; /health/tasks to watch it breathe. no more unbounded goroutine spray per report - upstream syncer runs concurrent now, dropped the dead mutex around repology fetches, reconciler single-flights instead of locking through the whole crawl - scheduler caps jobs per tick so an aligned fleet can't stampede the db - swatted a context-cancel bug that was quietly killing immediate syncs builds clean, race detector's calm.
31 lines
748 B
Go
31 lines
748 B
Go
package database
|
|
|
|
import "testing"
|
|
|
|
func TestEnvInt(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
set bool
|
|
val string
|
|
def int
|
|
want int
|
|
}{
|
|
{"unset uses default", false, "", 100, 100},
|
|
{"valid override", true, "200", 100, 200},
|
|
{"empty uses default", true, "", 100, 100},
|
|
{"non-numeric uses default", true, "lots", 100, 100},
|
|
{"zero ignored (cannot disable ceiling)", true, "0", 100, 100},
|
|
{"negative ignored", true, "-5", 100, 100},
|
|
}
|
|
for _, c := range cases {
|
|
t.Run(c.name, func(t *testing.T) {
|
|
const key = "REDFLAG_DB_TEST_ENVINT"
|
|
if c.set {
|
|
t.Setenv(key, c.val)
|
|
}
|
|
if got := envInt(key, c.def); got != c.want {
|
|
t.Errorf("envInt(%q, %d) = %d, want %d", c.val, c.def, got, c.want)
|
|
}
|
|
})
|
|
}
|
|
}
|