From 2273a5d63f76fce80a9059cb029d2354a1e1004e Mon Sep 17 00:00:00 2001 From: lkon <76028488+lkon2112@users.noreply.github.com> Date: Sun, 8 Nov 2026 19:33:33 +0800 Subject: [PATCH] test(openai): isolate orphan precheck allocation test --- .../openai_responses_orphan_precheck_test.go | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/backend/internal/service/openai_responses_orphan_precheck_test.go b/backend/internal/service/openai_responses_orphan_precheck_test.go index 9e41e8ee63..6da3edbf74 100644 --- a/backend/internal/service/openai_responses_orphan_precheck_test.go +++ b/backend/internal/service/openai_responses_orphan_precheck_test.go @@ -1,8 +1,13 @@ package service import ( + "context" + "os" + "os/exec" + "regexp" "strings" "testing" + "time" "github.com/stretchr/testify/require" "github.com/tidwall/gjson" @@ -126,6 +131,21 @@ func TestOpenAIResponsesOrphanPrecheckCompatibilityErrors(t *testing.T) { } func TestOpenAIResponsesOrphanPrecheckLargeEscapedContent(t *testing.T) { + // AllocsPerRun counts allocations across the process, including background + // goroutines left by other service tests. Measure only this case in a child. + const childEnv = "SUB2API_OPENAI_ORPHAN_ALLOC_TEST_CHILD" + if os.Getenv(childEnv) != "1" { + ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) + defer cancel() + executable, err := os.Executable() + require.NoError(t, err) + cmd := exec.CommandContext(ctx, executable, "-test.run=^"+regexp.QuoteMeta(t.Name())+"$", "-test.count=1") + cmd.Env = append(os.Environ(), childEnv+"=1") + output, err := cmd.CombinedOutput() + require.NoError(t, err, "isolated allocation test failed:\n%s", output) + return + } + body := []byte(`{"vendor":"` + strings.Repeat(`\n\"`, 1<<16) + `","input":[{"content":"` + strings.Repeat(`\n\"`, 1<<16) + `","type":"message"}]}`) require.False(t, openAIResponsesInputMayNeedOrphanCleanup(body)) allocations := testing.AllocsPerRun(5, func() {