on main help sign in
chore: fix broken performance tests:

Co-authored-by: Raphael Amorim <rapha850@gmail.com>

commit20a1704c5426d89c939587f7717cf33c4e858217 authorAndrey Nering <andreynering@users.noreply.github.com> dateMon 16 Jun 2025, 17:32 (1 year ago) parent93b41c9
2 files changed−54
internal/llm/tools/shell/comparison_test.go−29 internal/llm/tools/shell/shell_test.go−25
internal/llm/tools/shell/comparison_test.go−29
@@ -3,7 +3,6 @@ package shell
33import (
44 "context"
55 "os"
6− "runtime"
76 "testing"
87 "time"
98
@@ -32,34 +31,6 @@ func TestShellPerformanceComparison(t *testing.T) {
3231 t.Logf("Quick command took: %v", duration)
3332}
3433
35−func TestShellCPUUsageComparison(t *testing.T) {
36− tmpDir, err := os.MkdirTemp("", "shell-test")
37− require.NoError(t, err)
38− defer os.RemoveAll(tmpDir)
39−
40− shell := GetPersistentShell(tmpDir)
41− defer shell.Close()
42−
43− // Measure CPU and memory usage during a longer command
44− var m1, m2 runtime.MemStats
45− runtime.GC()
46− runtime.ReadMemStats(&m1)
47−
48− start := time.Now()
49− _, stderr, exitCode, _, err := shell.Exec(context.Background(), "sleep 0.1", 1000)
50− duration := time.Since(start)
51−
52− runtime.ReadMemStats(&m2)
53−
54− require.NoError(t, err)
55− assert.Equal(t, 0, exitCode)
56− assert.Empty(t, stderr)
57−
58− memGrowth := m2.Alloc - m1.Alloc
59− t.Logf("Sleep 0.1s command took: %v", duration)
60− t.Logf("Memory growth during polling: %d bytes", memGrowth)
61− t.Logf("GC cycles during test: %d", m2.NumGC-m1.NumGC)
62−}
6334
6435// Benchmark CPU usage during polling
6536func BenchmarkShellPolling(b *testing.B) {
internal/llm/tools/shell/shell_test.go−25
@@ -4,35 +4,10 @@ import (
44 "context"
55 "os"
66 "testing"
7− "time"
87
9− "github.com/stretchr/testify/assert"
108 "github.com/stretchr/testify/require"
119)
1210
13−func TestShellPerformanceImprovement(t *testing.T) {
14− // Create a temporary directory for the shell
15− tmpDir, err := os.MkdirTemp("", "shell-test")
16− require.NoError(t, err)
17− defer os.RemoveAll(tmpDir)
18−
19− shell := GetPersistentShell(tmpDir)
20− defer shell.Close()
21−
22− // Test that quick commands complete fast
23− start := time.Now()
24− stdout, stderr, exitCode, _, err := shell.Exec(context.Background(), "echo 'hello world'", 0)
25− duration := time.Since(start)
26−
27− require.NoError(t, err)
28− assert.Equal(t, 0, exitCode)
29− assert.Contains(t, stdout, "hello world")
30− assert.Empty(t, stderr)
31−
32− // Quick commands should complete very fast with our exponential backoff
33− assert.Less(t, duration, 50*time.Millisecond, "Quick command should complete fast with exponential backoff")
34−}
35−
3611// Benchmark to measure CPU efficiency
3712func BenchmarkShellQuickCommands(b *testing.B) {
3813 tmpDir, err := os.MkdirTemp("", "shell-bench")