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 := newPersistentShell(t.TempDir())
13
14	// Test quick command
15	start := time.Now()
16	stdout, stderr, exitCode, _, err := shell.Exec(t.Context(), "echo 'hello'", 0)
17	duration := time.Since(start)
18
19	require.NoError(t, err)
20	assert.Equal(t, 0, exitCode)
21	assert.Contains(t, stdout, "hello")
22	assert.Empty(t, stderr)
23
24	t.Logf("Quick command took: %v", duration)
25}
26
27// Benchmark CPU usage during polling
28func BenchmarkShellPolling(b *testing.B) {
29	shell := newPersistentShell(b.TempDir())
30
31	b.ReportAllocs()
32
33	for b.Loop() {
34		// Use a short sleep to measure polling overhead
35		_, _, exitCode, _, err := shell.Exec(b.Context(), "sleep 0.02", 0)
36		if err != nil || exitCode != 0 {
37			b.Fatalf("Command failed: %v, exit code: %d", err, exitCode)
38		}
39	}
40}