-
Notifications
You must be signed in to change notification settings - Fork 4
feat: add sane defaults for gRPC connection keepalive #72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
fdf7489
34260b2
b42b9cd
5b61b39
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -449,12 +449,78 @@ | |||||||||||||||
|
|
||||||||||||||||
| // --- Group 2: gRPC Server Options --- | ||||||||||||||||
|
|
||||||||||||||||
| func TestGetGRPCServerOptions_Default(t *testing.T) { | ||||||||||||||||
| func testKeepaliveBaseline() int { | ||||||||||||||||
| base := &cb{config: config.Config{}} | ||||||||||||||||
| return len(base.getGRPCServerOptions()) | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| func TestGetGRPCServerOptions_WithEnvconfigDefaults(t *testing.T) { | ||||||||||||||||
| // removed t.Parallel() — core tests mutate package-level globals | ||||||||||||||||
| c := &cb{config: config.Config{}} | ||||||||||||||||
| // Validates behavior when config has the envconfig default values (300, 1800, 30). | ||||||||||||||||
| // Keepalive option should be appended beyond the baseline. | ||||||||||||||||
| baseline := testKeepaliveBaseline() | ||||||||||||||||
| c := &cb{config: config.Config{ | ||||||||||||||||
| GRPCServerMaxConnectionIdleInSeconds: 300, | ||||||||||||||||
| GRPCServerMaxConnectionAgeInSeconds: 1800, | ||||||||||||||||
| GRPCServerMaxConnectionAgeGraceInSeconds: 30, | ||||||||||||||||
| }} | ||||||||||||||||
| opts := c.getGRPCServerOptions() | ||||||||||||||||
| if len(opts) < 2 { | ||||||||||||||||
| t.Fatalf("expected at least 2 server options, got %d", len(opts)) | ||||||||||||||||
| if len(opts) <= baseline { | ||||||||||||||||
| t.Fatalf("expected keepalive option beyond baseline %d, got %d", baseline, len(opts)) | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| func TestGetGRPCServerOptions_KeepaliveDisabledWithNegativeOne(t *testing.T) { | ||||||||||||||||
| // removed t.Parallel() — core tests mutate package-level globals | ||||||||||||||||
| // Setting all values to -1 should still append keepalive params (outer != 0 check), | ||||||||||||||||
| // but individual parameters are not set on ServerParameters (inner > 0 check), | ||||||||||||||||
| // so gRPC uses infinity for each. | ||||||||||||||||
| baseline := testKeepaliveBaseline() | ||||||||||||||||
| c := &cb{config: config.Config{ | ||||||||||||||||
| GRPCServerMaxConnectionIdleInSeconds: -1, | ||||||||||||||||
| GRPCServerMaxConnectionAgeInSeconds: -1, | ||||||||||||||||
| GRPCServerMaxConnectionAgeGraceInSeconds: -1, | ||||||||||||||||
| }} | ||||||||||||||||
| opts := c.getGRPCServerOptions() | ||||||||||||||||
| if len(opts) <= baseline { | ||||||||||||||||
| t.Fatalf("expected keepalive option beyond baseline %d, got %d", baseline, len(opts)) | ||||||||||||||||
| } | ||||||||||||||||
|
ankurs marked this conversation as resolved.
|
||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| func TestGetGRPCServerOptions_KeepaliveMixed(t *testing.T) { | ||||||||||||||||
| // removed t.Parallel() — core tests mutate package-level globals | ||||||||||||||||
| // Mix of -1 (disabled) and positive (enabled) values should still append | ||||||||||||||||
| // keepalive params relative to the all-zero baseline. | ||||||||||||||||
| baseline := testKeepaliveBaseline() | ||||||||||||||||
| c := &cb{config: config.Config{ | ||||||||||||||||
| GRPCServerMaxConnectionIdleInSeconds: -1, | ||||||||||||||||
| GRPCServerMaxConnectionAgeInSeconds: 1800, | ||||||||||||||||
| GRPCServerMaxConnectionAgeGraceInSeconds: 30, | ||||||||||||||||
| }} | ||||||||||||||||
| opts := c.getGRPCServerOptions() | ||||||||||||||||
| if len(opts) <= baseline { | ||||||||||||||||
| t.Fatalf("expected keepalive option beyond baseline %d, got %d", baseline, len(opts)) | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| func TestGetGRPCServerOptions_KeepaliveAllZero(t *testing.T) { | ||||||||||||||||
| // removed t.Parallel() — core tests mutate package-level globals | ||||||||||||||||
| // All zeros should NOT add keepalive params (outer != 0 check is false). | ||||||||||||||||
| // Compare against a positive-value config to prove zero omits keepalive. | ||||||||||||||||
| zeroConfig := &cb{config: config.Config{ | ||||||||||||||||
| GRPCServerMaxConnectionIdleInSeconds: 0, | ||||||||||||||||
| GRPCServerMaxConnectionAgeInSeconds: 0, | ||||||||||||||||
| GRPCServerMaxConnectionAgeGraceInSeconds: 0, | ||||||||||||||||
| }} | ||||||||||||||||
| positiveConfig := &cb{config: config.Config{ | ||||||||||||||||
| GRPCServerMaxConnectionIdleInSeconds: 300, | ||||||||||||||||
| GRPCServerMaxConnectionAgeInSeconds: 1800, | ||||||||||||||||
| GRPCServerMaxConnectionAgeGraceInSeconds: 30, | ||||||||||||||||
| }} | ||||||||||||||||
| zeroOpts := zeroConfig.getGRPCServerOptions() | ||||||||||||||||
| positiveOpts := positiveConfig.getGRPCServerOptions() | ||||||||||||||||
| if len(zeroOpts) >= len(positiveOpts) { | ||||||||||||||||
| t.Fatalf("expected fewer options with all-zero keepalive than positive, got %d vs %d", len(zeroOpts), len(positiveOpts)) | ||||||||||||||||
| } | ||||||||||||||||
|
ankurs marked this conversation as resolved.
|
||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
|
|
@@ -1303,7 +1369,7 @@ | |||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| func TestConfigureInterceptors_BothBranches(t *testing.T) { | ||||||||||||||||
| ConfigureInterceptors(true, "X-My-Trace", "info", false) | ||||||||||||||||
| ConfigureInterceptors(true, "X-My-Trace", "info", false, 60) | ||||||||||||||||
|
Check failure on line 1372 in core_coverage_test.go
|
||||||||||||||||
| } | ||||||||||||||||
|
Comment on lines
1371
to
1373
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix the Line 1372 passes five arguments, but Suggested fix func TestConfigureInterceptors_BothBranches(t *testing.T) {
- ConfigureInterceptors(true, "X-My-Trace", "info", false, 60)
+ ConfigureInterceptors(true, "X-My-Trace", "info", false)
}📝 Committable suggestion
Suggested change
🧰 Tools🪛 GitHub Actions: Go[error] 1372-1372: golangci-lint build/test failure: too many arguments in call to ConfigureInterceptors in core_coverage_test.go:1372:59. 🪛 GitHub Check: lint[failure] 1372-1372: 🪛 GitHub Check: test[failure] 1372-1372: 🪛 golangci-lint (2.11.4)[error] 1372-1372: too many arguments in call to ConfigureInterceptors (typecheck) 🤖 Prompt for AI Agents |
||||||||||||||||
|
|
||||||||||||||||
| func TestConfig_Validate_HTTPCompressionMinSize(t *testing.T) { | ||||||||||||||||
|
|
||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.