mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-10-24 04:33:17 +00:00
Compose current upstream allocation guard with reviewed maintenance repairs
Preserve reviewed tip888d918ba1and startup-fetched upstream8e14b4a63eunchanged in history. Resolve the allocation-test conflict by retaining the upstream boolean entry point with the reviewed bounded child launcher, strict measurement witness, escaping root sink and background-allocation control. No runtime or threshold changes; no stopped refresh replay. Contract-Neutral: Test-only additive reconciliation of allocation-isolation repairs; runtime contracts unchanged. Change-source: pulse-maintainer
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -198,20 +199,38 @@ func TestNormalizeSegment(t *testing.T) {
|
||||
// could copy a short segment into a stack buffer and hide the allocation.
|
||||
var normalizeSegmentSink string
|
||||
|
||||
// allocIsolationEnv names the test that a child process re-runs on its own.
|
||||
const allocIsolationEnv = "PULSE_TEST_ALLOC_ISOLATION"
|
||||
|
||||
// measureAllocsInIsolation keeps the upstream test entry point while using the
|
||||
// bounded, measurement-marked child launcher shared with the background-fixture
|
||||
// control. The child flag and upstream environment marker both select the actual
|
||||
// measurement; the parent must observe that measurement, not just a passing test.
|
||||
func measureAllocsInIsolation(t *testing.T) bool {
|
||||
t.Helper()
|
||||
if *routeAllocationChild || os.Getenv(allocIsolationEnv) == t.Name() {
|
||||
t.Cleanup(func() { t.Log("ROUTE_ALLOCATION_MEASURED " + t.Name()) })
|
||||
return true
|
||||
}
|
||||
runRouteAllocationTest(t, t.Name())
|
||||
return false
|
||||
}
|
||||
|
||||
func TestNormalizeSegment_DoesNotAllocate(t *testing.T) {
|
||||
isolatedRouteAllocationCheck(t, func() {
|
||||
for _, seg := range []string{
|
||||
"12345",
|
||||
"550e8400-e29b-41d4-a716-446655440000",
|
||||
"abcdefghijklmnopqrstuvwxyz1234567890abcdef",
|
||||
"resources",
|
||||
"metrics-store",
|
||||
} {
|
||||
if allocs := testing.AllocsPerRun(100, func() { normalizeSegmentSink = normalizeSegment(seg) }); allocs != 0 {
|
||||
t.Errorf("normalizeSegment(%q) allocated %v times per call, want 0", seg, allocs)
|
||||
}
|
||||
if !measureAllocsInIsolation(t) {
|
||||
return
|
||||
}
|
||||
for _, seg := range []string{
|
||||
"12345",
|
||||
"550e8400-e29b-41d4-a716-446655440000",
|
||||
"abcdefghijklmnopqrstuvwxyz1234567890abcdef",
|
||||
"resources",
|
||||
"metrics-store",
|
||||
} {
|
||||
if allocs := testing.AllocsPerRun(100, func() { normalizeSegmentSink = normalizeSegment(seg) }); allocs != 0 {
|
||||
t.Errorf("normalizeSegment(%q) allocated %v times per call, want 0", seg, allocs)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeRoute(t *testing.T) {
|
||||
@@ -273,13 +292,14 @@ func TestNormalizeRoute(t *testing.T) {
|
||||
var normalizeRouteSink string
|
||||
|
||||
func TestNormalizeRoute_RootFastPathDoesNotAllocate(t *testing.T) {
|
||||
isolatedRouteAllocationCheck(t, func() {
|
||||
for _, path := range []string{"/", ""} {
|
||||
if allocs := testing.AllocsPerRun(100, func() { normalizeRouteSink = normalizeRoute(path) }); allocs != 0 {
|
||||
t.Errorf("normalizeRoute(%q) allocated %v times per call, want 0", path, allocs)
|
||||
}
|
||||
if !measureAllocsInIsolation(t) {
|
||||
return
|
||||
}
|
||||
for _, path := range []string{"/", ""} {
|
||||
if allocs := testing.AllocsPerRun(100, func() { normalizeRouteSink = normalizeRoute(path) }); allocs != 0 {
|
||||
t.Errorf("normalizeRoute(%q) allocated %v times per call, want 0", path, allocs)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user