Watch
1
0
Fork
You've already forked RedFlag
0
RedFlag/server/internal/database/db_test.go
Fimeg 82018bfb80 taught the rocks to stop tripping over each other under load
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.
2026-06-07 19:17:08 -04:00

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)
}
})
}
}