@@ -28,7 +28,7 @@ func TestShellPerformanceComparison(t *testing.T) {
assert.Equal(t, 0, exitCode)
assert.Contains(t, stdout, "hello")
assert.Empty(t, stderr)
-
+
t.Logf("Quick command took: %v", duration)
}
@@ -48,13 +48,13 @@ func TestShellCPUUsageComparison(t *testing.T) {
start := time.Now()
_, stderr, exitCode, _, err := shell.Exec(context.Background(), "sleep 0.1", 1000)
duration := time.Since(start)
-
+
runtime.ReadMemStats(&m2)
require.NoError(t, err)
assert.Equal(t, 0, exitCode)
assert.Empty(t, stderr)
-
+
memGrowth := m2.Alloc - m1.Alloc
t.Logf("Sleep 0.1s command took: %v", duration)
t.Logf("Memory growth during polling: %d bytes", memGrowth)
@@ -72,7 +72,7 @@ func BenchmarkShellPolling(b *testing.B) {
b.ResetTimer()
b.ReportAllocs()
-
+
for i := 0; i < b.N; i++ {
// Use a short sleep to measure polling overhead
_, _, exitCode, _, err := shell.Exec(context.Background(), "sleep 0.02", 500)
@@ -80,4 +80,4 @@ func BenchmarkShellPolling(b *testing.B) {
b.Fatalf("Command failed: %v, exit code: %d", err, exitCode)
}
}
-}
+}
@@ -192,10 +192,10 @@ echo $EXEC_EXIT_CODE > %s
// Use exponential backoff polling
pollInterval := 1 * time.Millisecond
maxPollInterval := 100 * time.Millisecond
-
+
ticker := time.NewTicker(pollInterval)
defer ticker.Stop()
-
+
for {
select {
case <-ctx.Done():
@@ -219,7 +219,7 @@ echo $EXEC_EXIT_CODE > %s
return
}
}
-
+
// Exponential backoff to reduce CPU usage for longer-running commands
if pollInterval < maxPollInterval {
pollInterval = time.Duration(float64(pollInterval) * 1.5)
@@ -28,7 +28,7 @@ func TestShellPerformanceImprovement(t *testing.T) {
assert.Equal(t, 0, exitCode)
assert.Contains(t, stdout, "hello world")
assert.Empty(t, stderr)
-
+
// Quick commands should complete very fast with our exponential backoff
assert.Less(t, duration, 50*time.Millisecond, "Quick command should complete fast with exponential backoff")
}
@@ -44,11 +44,11 @@ func BenchmarkShellQuickCommands(b *testing.B) {
b.ResetTimer()
b.ReportAllocs()
-
+
for i := 0; i < b.N; i++ {
_, _, exitCode, _, err := shell.Exec(context.Background(), "echo test", 0)
if err != nil || exitCode != 0 {
b.Fatalf("Command failed: %v, exit code: %d", err, exitCode)
}
}
-}
+}