Artifact a46471c77240b8c4b4dc7890cce98cf15fc3dda8fd59986d6866ee12edda9ca6:
- File
internal/timing/timing_test.go
— part of check-in
[45bb75ade2]
at
2026-08-17 21:26:48
on branch trunk
— work: bound bulk operations; footer times keep their precision
Nothing in quarry limited concurrency — every zit subprocess ran in the request goroutine with the arrival rate as the only bound. work.Lane is a concurrency limit plus a queue cap that SHEDS past it: a request accepted into a queue it cannot be served from consumes the capacity that would have served someone else.
Wired to archive first, which buffers 256 MiB per request on an anonymous route. That is latent rather than live — archive 503s on zit#97 — which is why the bound belongs there now, so the endpoint is born bounded rather than acquiring a limit after someone finds it.
Footer precision: '<1ms' was true and useless once most pages went sub-millisecond, collapsing the interesting range into one label. timing.Format keeps ~3 significant figures across five orders of magnitude, so 900µs and 90µs no longer read the same. Fossil has the mirror-image bug: three decimals of seconds prints everything faster than a millisecond as 0.000s. (user: dmestas, size: 1865) [annotate] [blame] [check-ins using]
package timing import ( "strings" "testing" "time" ) // "<1ms" was true and useless. Most pages are sub-millisecond now, so // the floor collapsed the interesting range into one label — an // improvement from 900µs to 90µs was invisible. Fossil has the // mirror-image problem: three decimals of seconds means everything // faster than a millisecond prints as "0.000s". func TestFormatKeepsPrecisionBelowAMillisecond(t *testing.T) { for _, tc := range []struct { d time.Duration want string }{ {4200 * time.Nanosecond, "4.2µs"}, {421 * time.Microsecond, "421µs"}, {999 * time.Microsecond, "999µs"}, {4210 * time.Microsecond, "4.21ms"}, {42100 * time.Microsecond, "42.1ms"}, {536 * time.Millisecond, "536.0ms"}, {2632 * time.Millisecond, "2.63s"}, {0, "0"}, } { if got := Format(tc.d); got != tc.want { t.Errorf("Format(%v) = %q, want %q", tc.d, got, tc.want) } } // The whole point: two sub-millisecond durations an order of // magnitude apart must not render identically. if Format(900*time.Microsecond) == Format(90*time.Microsecond) { t.Error("900µs and 90µs render the same — the floor is back") } } // The breakdown names only layers that did work, busiest first. func TestBreakdownOrdersByCost(t *testing.T) { tm := &Timing{by: map[Category]*entry{}} tm.Add(SQL, 2*time.Millisecond) tm.Add(Zit, 150*time.Millisecond) tm.Add(Zit, 100*time.Millisecond) got := tm.Breakdown() if !strings.HasPrefix(got, "zit ") { t.Errorf("breakdown = %q, want the costliest layer first", got) } if !strings.Contains(got, "×2") { t.Errorf("breakdown = %q, want the zit call count", got) } if strings.Contains(got, "chat") || strings.Contains(got, "http") { t.Errorf("breakdown = %q, want idle layers omitted", got) } if (*Timing)(nil).Breakdown() != "" { t.Error("nil Timing must render empty") } }