1package shell
2
3import (
4 "testing"
5 "time"
6
7 "github.com/stretchr/testify/assert"
8 "github.com/stretchr/testify/require"
9)
10
11func TestShellPerformanceComparison(t *testing.T) {
12 shell := NewShell(&Options{WorkingDir: t.TempDir()})
13
14 // Test quick command
15 start := time.Now()
16 stdout, stderr, err := shell.Exec(t.Context(), "echo 'hello'")
17 exitCode := ExitCode(err)
18 duration := time.Since(start)
19
20 require.NoError(t, err)
21 assert.Equal(t, 0, exitCode)
22 assert.Contains(t, stdout, "hello")
23 assert.Empty(t, stderr)
24
25 t.Logf("Quick command took: %v", duration)
26}
27
28// Benchmark CPU usage during polling
29func BenchmarkShellPolling(b *testing.B) {
30 shell := NewShell(&Options{WorkingDir: b.TempDir()})
31
32 b.ReportAllocs()
33
34 for b.Loop() {
35 // Use a short sleep to measure polling overhead
36 _, _, err := shell.Exec(b.Context(), "sleep 0.02")
37 exitCode := ExitCode(err)
38 if err != nil || exitCode != 0 {
39 b.Fatalf("Command failed: %v, exit code: %d", err, exitCode)
40 }
41 }
42}