@@ -1240,35 +1240,40 @@ func Test_MemoryUsage_SlidingWindow_vs_NoWindow(t *testing.T) {
1240
1240
os .Setenv ("GITHUB_MCP_PROFILING_ENABLED" , "true" )
1241
1241
defer os .Unsetenv ("GITHUB_MCP_PROFILING_ENABLED" )
1242
1242
1243
- // Initialize the global profiler
1244
1243
profiler .InitFromEnv (nil )
1245
-
1246
1244
ctx := context .Background ()
1247
1245
1248
1246
debug .SetGCPercent (- 1 )
1249
1247
defer debug .SetGCPercent (100 )
1250
1248
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
+
1253
1256
profile1 , err1 := profiler .ProfileFuncWithMetrics (ctx , "sliding_window" , func () (int , int64 , error ) {
1254
1257
resp1 , err := http .Get (testServer .URL )
1255
1258
if err != nil {
1256
1259
return 0 , 0 , err
1257
1260
}
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
1259
1262
content , totalLines , _ , err := buffer .ProcessResponseAsRingBufferToEnd (resp1 , bufferSize ) //nolint:bodyclose
1260
1263
return totalLines , int64 (len (content )), err
1261
1264
})
1262
1265
require .NoError (t , err1 )
1263
1266
1264
- runtime .GC ()
1265
- runtime .GC ()
1267
+ for i := 0 ; i < 3 ; i ++ {
1268
+ runtime .GC ()
1269
+ }
1270
+
1266
1271
profile2 , err2 := profiler .ProfileFuncWithMetrics (ctx , "no_window" , func () (int , int64 , error ) {
1267
1272
resp2 , err := http .Get (testServer .URL )
1268
1273
if err != nil {
1269
1274
return 0 , 0 , err
1270
1275
}
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
1272
1277
1273
1278
allContent , err := io .ReadAll (resp2 .Body )
1274
1279
if err != nil {
@@ -1310,6 +1315,7 @@ func Test_MemoryUsage_SlidingWindow_vs_NoWindow(t *testing.T) {
1310
1315
float64 (profile2 .MemoryDelta )/ 1024 / 1024 ,
1311
1316
float64 (profile1 .MemoryDelta )/ 1024 / 1024 )
1312
1317
1318
+ t .Logf ("Baseline: %d bytes" , baselineStats .Alloc )
1313
1319
t .Logf ("Sliding window: %s" , profile1 .String ())
1314
1320
t .Logf ("No window: %s" , profile2 .String ())
1315
1321
}
0 commit comments