@@ -1240,35 +1240,40 @@ func Test_MemoryUsage_SlidingWindow_vs_NoWindow(t *testing.T) {
12401240 os .Setenv ("GITHUB_MCP_PROFILING_ENABLED" , "true" )
12411241 defer os .Unsetenv ("GITHUB_MCP_PROFILING_ENABLED" )
12421242
1243- // Initialize the global profiler
12441243 profiler .InitFromEnv (nil )
1245-
12461244 ctx := context .Background ()
12471245
12481246 debug .SetGCPercent (- 1 )
12491247 defer debug .SetGCPercent (100 )
12501248
1251- runtime .GC ()
1252- runtime .GC ()
1249+ for i := 0 ; i < 3 ; i ++ {
1250+ runtime .GC ()
1251+ }
1252+
1253+ var baselineStats runtime.MemStats
1254+ runtime .ReadMemStats (& baselineStats )
1255+
12531256 profile1 , err1 := profiler .ProfileFuncWithMetrics (ctx , "sliding_window" , func () (int , int64 , error ) {
12541257 resp1 , err := http .Get (testServer .URL )
12551258 if err != nil {
12561259 return 0 , 0 , err
12571260 }
1258- defer resp1 .Body .Close () //nolint:bodyclose // Response body is closed in downloadLogContent, but we need to return httpResp
1261+ defer resp1 .Body .Close () //nolint:bodyclose
12591262 content , totalLines , _ , err := buffer .ProcessResponseAsRingBufferToEnd (resp1 , bufferSize ) //nolint:bodyclose
12601263 return totalLines , int64 (len (content )), err
12611264 })
12621265 require .NoError (t , err1 )
12631266
1264- runtime .GC ()
1265- runtime .GC ()
1267+ for i := 0 ; i < 3 ; i ++ {
1268+ runtime .GC ()
1269+ }
1270+
12661271 profile2 , err2 := profiler .ProfileFuncWithMetrics (ctx , "no_window" , func () (int , int64 , error ) {
12671272 resp2 , err := http .Get (testServer .URL )
12681273 if err != nil {
12691274 return 0 , 0 , err
12701275 }
1271- defer resp2 .Body .Close () //nolint:bodyclose // Response body is closed in downloadLogContent, but we need to return httpResp
1276+ defer resp2 .Body .Close () //nolint:bodyclose
12721277
12731278 allContent , err := io .ReadAll (resp2 .Body )
12741279 if err != nil {
@@ -1310,6 +1315,7 @@ func Test_MemoryUsage_SlidingWindow_vs_NoWindow(t *testing.T) {
13101315 float64 (profile2 .MemoryDelta )/ 1024 / 1024 ,
13111316 float64 (profile1 .MemoryDelta )/ 1024 / 1024 )
13121317
1318+ t .Logf ("Baseline: %d bytes" , baselineStats .Alloc )
13131319 t .Logf ("Sliding window: %s" , profile1 .String ())
13141320 t .Logf ("No window: %s" , profile2 .String ())
13151321}
0 commit comments