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