Enhance stress test performance assertions for CI environments

- Updated the performance assertion for no-op operations in the stress test to account for slower execution times in CI environments, allowing a maximum time of 15ms instead of 5ms.
- Added comments to clarify expected performance metrics for local versus CI runs, improving test documentation and understanding.
This commit is contained in:
Max 2025-11-29 20:17:28 +08:00
parent fab6d19c14
commit 9c7be8401a

View file

@ -3,6 +3,7 @@ package context_test
import ( import (
stdContext "context" stdContext "context"
"fmt" "fmt"
"os"
"runtime" "runtime"
"sync" "sync"
"testing" "testing"
@ -381,9 +382,14 @@ func TestStressNoOpTracePerformance(t *testing.T) {
t.Logf("Start memory: %d MB", startMemory/1024/1024) t.Logf("Start memory: %d MB", startMemory/1024/1024)
t.Logf("End memory: %d MB", endMemory/1024/1024) t.Logf("End memory: %d MB", endMemory/1024/1024)
// No-op operations should be reasonably fast (< 5ms per iteration) // No-op operations should be reasonably fast
// This includes V8 call overhead, not just the no-op operation itself // Note: CI environments may be slower due to resource limits
assert.Less(t, avgTimePerOp, 5*time.Millisecond, "No-op operations should be fast") // Local: ~2ms, CI: ~10ms
maxTimePerOp := 5 * time.Millisecond
if os.Getenv("CI") != "" || os.Getenv("GITHUB_ACTIONS") != "" {
maxTimePerOp = 15 * time.Millisecond // More lenient for CI
}
assert.Less(t, avgTimePerOp, maxTimePerOp, "No-op operations should be fast")
// No-op operations should not leak memory (< 5MB growth) // No-op operations should not leak memory (< 5MB growth)
if endMemory > startMemory { if endMemory > startMemory {