test(gateway): isolate signed-history allocation measurement

This commit is contained in:
r266-tech committed 2026-11-07 18:36:52 +08:00
1 parent 38605c1fe8
commit 217925ca0b
1 file changed
+17
@@ -3,6 +3,8 @@ package service
import (
"bytes"
"encoding/json"
"os"
"os/exec"
"strings"
"testing"
@@ -75,6 +77,21 @@ func signedThinkingHistoryBody() []byte {
}
func TestFilterThinkingBlocksSignedHistorySkipsDecode(t *testing.T) {
// AllocsPerRun reads process-wide counters. Background workers from other
// service tests can otherwise make unchanged signed history fail this check.
const isolatedEnv = "SUB2API_TEST_SIGNED_HISTORY_ALLOCS"
if os.Getenv(isolatedEnv) != "1" {
binary, err := os.Executable()
require.NoError(t, err)
cmd := exec.CommandContext(t.Context(), binary,
"-test.run=^TestFilterThinkingBlocksSignedHistorySkipsDecode$",
"-test.count=1", "-test.timeout=30s")
cmd.Env = append(os.Environ(), isolatedEnv+"=1")
output, err := cmd.CombinedOutput()
require.NoError(t, err, "%s", output)
return
}
body := signedThinkingHistoryBody()
allocs := testing.AllocsPerRun(5, func() {
got := filterThinkingBlocksInternal(body, false)