From 2b967d42a8e9f562da290b266ab87b98ba289a56 Mon Sep 17 00:00:00 2001 From: Frederic BIDON Date: Fri, 14 Aug 2026 18:13:46 +0200 Subject: [PATCH] test(genspec-tui): count every allocation when checking attribution MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit TestProfilerCapturesARun allocated a megabyte and asserted that the profiler attributed it. At the default rate the heap profiler samples one allocation per 512 KiB, so that megabyte is a Poisson draw with a mean of two, and the profile comes back empty about one run in seven — measured at 4 failures in 30 runs locally, independently of the toolchain. Pin MemProfileRate to 1 for the test, as the fabricated-record tests alongside it already do, so the assertion is about attribution rather than about luck. The runtime honours rate 1 from the very next allocation, with no threshold carried over from the previous rate. Nothing in the profiler changes: sampling is what the default rate means, and a phase whose sites were not sampled already says so on the card. Signed-off-by: Frederic BIDON --- cmd/genspec-tui/internal/ux/scan/profile_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cmd/genspec-tui/internal/ux/scan/profile_test.go b/cmd/genspec-tui/internal/ux/scan/profile_test.go index 5f71be7d..18f7ddad 100644 --- a/cmd/genspec-tui/internal/ux/scan/profile_test.go +++ b/cmd/genspec-tui/internal/ux/scan/profile_test.go @@ -196,6 +196,12 @@ func TestProfilerDisabled(t *testing.T) { } func TestProfilerCapturesARun(t *testing.T) { + // At the default rate the heap profiler samples one allocation per 512 KiB, so a megabyte of test allocations is a + // Poisson draw with a mean of two: it comes back empty about one run in seven, whatever the machine or the + // toolchain. Counting every allocation makes the assertion below about attribution rather than about luck, and the + // runtime honours rate 1 from the next allocation - there is no threshold left over from the old rate. + countEveryAllocation(t) + dir := t.TempDir() p := newProfiler(Profiling{Enabled: true, Dir: dir})