Skip to content

Commit 1b45e5d

Browse files
committed
Fix default backoff parsing
1 parent 8361fa0 commit 1b45e5d

2 files changed

Lines changed: 28 additions & 9 deletions

File tree

cmd/gabs/main.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func main() {
9191
httpAddrNew = fs.String("addr", "localhost:8080", "HTTP server address (for 'gabs server http' command)")
9292
configDir = fs.String("configDir", "", "Override GABS config directory")
9393
logLevel = fs.String("log-level", "info", "Log level: trace|debug|info|warn|error")
94-
backoff = fs.String("reconnectBackoff", defaultBackoff, "Reconnect backoff window, e.g. '100ms..5s'")
94+
backoff = fs.String("reconnectBackoff", defaultBackoff, "Reconnect backoff window, e.g. '100ms..1s'")
9595
grace = fs.Duration("grace", 3*time.Second, "Graceful stop timeout before kill")
9696
)
9797

@@ -658,23 +658,23 @@ func resolveMacOSAppBundle(appPath string) (string, error) {
658658

659659
func parseBackoff(s string) (time.Duration, time.Duration, error) {
660660
// Parse "<min>..<max>" format
661-
// Examples: "100ms..5s", "1s..30s", "250ms..inf"
661+
// Examples: "100ms..1s", "1s..30s", "250ms..inf"
662662
switch {
663663
case s == "", s == defaultBackoff:
664-
return 100 * time.Millisecond, 5 * time.Second, nil
664+
return 100 * time.Millisecond, 1 * time.Second, nil
665665
default:
666666
// Split on ".."
667667
parts := strings.Split(s, "..")
668668
if len(parts) != 2 {
669-
return 100 * time.Millisecond, 5 * time.Second, fmt.Errorf("invalid format, expected 'min..max'")
669+
return 100 * time.Millisecond, 1 * time.Second, fmt.Errorf("invalid format, expected 'min..max'")
670670
}
671671

672672
min, err := time.ParseDuration(parts[0])
673673
if err != nil {
674-
return 100 * time.Millisecond, 5 * time.Second, fmt.Errorf("invalid min duration: %w", err)
674+
return 100 * time.Millisecond, 1 * time.Second, fmt.Errorf("invalid min duration: %w", err)
675675
}
676676
if min < 0 {
677-
return 100 * time.Millisecond, 5 * time.Second, fmt.Errorf("min duration cannot be negative")
677+
return 100 * time.Millisecond, 1 * time.Second, fmt.Errorf("min duration cannot be negative")
678678
}
679679

680680
var max time.Duration
@@ -683,15 +683,15 @@ func parseBackoff(s string) (time.Duration, time.Duration, error) {
683683
} else {
684684
max, err = time.ParseDuration(parts[1])
685685
if err != nil {
686-
return 100 * time.Millisecond, 5 * time.Second, fmt.Errorf("invalid max duration: %w", err)
686+
return 100 * time.Millisecond, 1 * time.Second, fmt.Errorf("invalid max duration: %w", err)
687687
}
688688
if max < 0 {
689-
return 100 * time.Millisecond, 5 * time.Second, fmt.Errorf("max duration cannot be negative")
689+
return 100 * time.Millisecond, 1 * time.Second, fmt.Errorf("max duration cannot be negative")
690690
}
691691
}
692692

693693
if min > max {
694-
return 100 * time.Millisecond, 5 * time.Second, fmt.Errorf("min duration (%v) cannot be greater than max duration (%v)", min, max)
694+
return 100 * time.Millisecond, 1 * time.Second, fmt.Errorf("min duration (%v) cannot be greater than max duration (%v)", min, max)
695695
}
696696

697697
return min, max, nil

cmd/gabs/main_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package main
2+
3+
import (
4+
"testing"
5+
"time"
6+
)
7+
8+
func TestParseBackoffDefault(t *testing.T) {
9+
min, max, err := parseBackoff(defaultBackoff)
10+
if err != nil {
11+
t.Fatalf("parseBackoff returned error: %v", err)
12+
}
13+
if min != 100*time.Millisecond {
14+
t.Fatalf("expected min 100ms, got %v", min)
15+
}
16+
if max != time.Second {
17+
t.Fatalf("expected max 1s, got %v", max)
18+
}
19+
}

0 commit comments

Comments
 (0)