Skip to content

fix integration tests#264

Merged
alienvspredator merged 1 commit intomainfrom
fix/integration-tests
Mar 25, 2026
Merged

fix integration tests#264
alienvspredator merged 1 commit intomainfrom
fix/integration-tests

Conversation

@alienvspredator
Copy link
Copy Markdown
Member

@alienvspredator alienvspredator commented Mar 24, 2026

This PR fixes various errors in the integration tests:

  • The service didn't return a proper exit code and the tests weren't able to validate whether a process exited normally or abnormally.
  • We tried to start a service on a unix socket, however there's a hard limit of 108 symbols on a unix socket filepath. This was resolved by creating a temporary directory for the process files via OS system call.

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Improved error handling in shutdown flows to properly capture and return errors.
    • Enhanced error logging with structured context for better diagnostics.
  • Tests

    • Refactored test infrastructure for improved isolation and reliability.
    • Added conditional error logging in test server startup.
  • Chores

    • Optimized test command execution for integration tests.
    • Improved command output formatting by suppressing unnecessary usage messages on errors.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 24, 2026

📝 Walkthrough

Walkthrough

This pull request refactors test infrastructure by removing a cmdName parameter from the initInfra helper function, replaces fmt-based stderr output with structured logging throughout the codebase, improves error logging with conditional checks in gRPC servers, updates test assertions to properly expect errors from the Main function, and adds enhanced error logging in HTTP server listener creation and OIDC mapping removal operations.

Changes

Cohort / File(s) Summary
Build Configuration
Makefile
Adjusted gotestsum integration test invocation to pass GOCOVERDIR as part of the shell statement instead of as a separate token.
Application Startup & Logging
cmd/session-manager/main.go
Replaced fmt.Fprintln stderr output and graceful shutdown message with structured logging via slogctx, removing fmt-based stderr output on startup failure.
Test Infrastructure Updates
integration/api-server-status_test.go, integration/api-server_test.go, integration/housekeeper_test.go, integration/infra_test.go
Removed cmdName parameter from initInfra calls; infra_test.go now generates per-test temporary directories with fixed socket filename and enforces 108-character UNIX socket path limit; adjusted server warm-up polling and replaced manual URL concatenation with url.JoinPath.
gRPC Server Error Logging
integration/grpc_test.go, integration/session_grpc_test.go
Conditionally log server startup errors only when err != nil, preventing spurious logging on successful shutdown.
Business Logic Error Handling
internal/business/business.go, internal/business/business_test.go
Main now returns captured shutdown error instead of always returning nil; updated test assertions to expect errors instead of nil for invalid configuration scenarios.
HTTP Server & Logging
internal/business/server/http_server.go
Added structured error log with network and address details on listener creation failure.
CLI & gRPC Enhancements
internal/cmdutils/cmdutils.go, internal/grpc/oidcmapping.go
Set SilenceUsage: true on Cobra command; improved OIDC mapping removal error handling by logging warnings for ErrNotFound and errors only for other failures.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A hop through logs, refined and bright,
Errors now sing in structured light,
Tests reshape with socket care,
Graceful handling everywhere—
Refactored paths, errors fair! ✨

🚥 Pre-merge checks | ❌ 3

❌ Failed checks (1 warning, 2 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'fix integration tests' is vague and generic, lacking specificity about the primary changes made in the changeset. Provide a more specific title that highlights the main fix, such as 'fix: resolve integration tests with unix socket path limits and exit code handling'.
Description check ❓ Inconclusive The PR description provides a clear overview of the issues being fixed but lacks the structured format with PR title category, special reviewer notes, and release note sections specified in the template. Reformat the description to follow the template: add PR title with category prefix (e.g., 'fix: integration tests'), include structured sections for 'What this PR does', 'Special notes for your reviewer', and 'Release note'.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/integration-tests

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (4)
internal/grpc/oidcmapping.go (1)

103-104: Consider downgrading ErrNotFound log level to Debug to reduce noise.

If remove is intentionally idempotent, missing-tenant removals are an expected path and Warn can create alert fatigue.

♻️ Optional log-level tweak
-		} else {
-			slogctx.Warn(ctx, "RemoveOIDCMapping is called but the tenant does not exist", "error", err)
+		} else {
+			slogctx.Debug(ctx, "RemoveOIDCMapping called for non-existent tenant", "error", err)
 		}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal/grpc/oidcmapping.go` around lines 103 - 104, The current branch in
RemoveOIDCMapping logs missing-tenant errors with slogctx.Warn which is noisy
for idempotent removals; change the logic to detect the not-found condition
(e.g., errors.Is(err, ErrNotFound) or comparing with ErrNotFound) and log it at
Debug level with slogctx.Debug (including the same context/error), while
retaining slogctx.Warn for other unexpected errors so only real failures remain
at warn level.
integration/session_grpc_test.go (1)

205-210: Same scoping suggestion as in grpc_test.go.

The conditional logging is correct. For consistency with the suggestion in grpc_test.go, consider using err := to scope the variable to the goroutine and avoid the theoretical data race.

Suggested fix
 	// start
 	go func() {
-		err = srv.Serve(lis)
+		err := srv.Serve(lis)
 		if err != nil {
 			slogctx.Error(ctx, "error while starting session server", "error", err)
 		}
 	}()
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@integration/session_grpc_test.go` around lines 205 - 210, The goroutine that
calls srv.Serve(lis) reuses the outer variable err; change it to declare a new
scoped variable inside the goroutine (use err := srv.Serve(lis)) so the error
returned by srv.Serve is local to that goroutine and avoids a potential data
race when logging with slogctx.Error; update the anonymous goroutine block that
currently assigns to err to instead use a short declaration and keep the
existing conditional log using the local err variable.
integration/grpc_test.go (1)

333-338: Conditional error logging looks good, but consider scoping err to the goroutine.

The if err != nil guard correctly avoids logging nil on graceful shutdown. However, err = srv.Serve(lis) assigns to the outer function's err variable (declared at line 324), creating a theoretical data race since the outer function returns before the goroutine runs.

Suggested fix: scope `err` to the goroutine
 	// start
 	go func() {
-		err = srv.Serve(lis)
+		err := srv.Serve(lis)
 		if err != nil {
 			slogctx.Error(ctx, "error while starting server", "error", err)
 		}
 	}()
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@integration/grpc_test.go` around lines 333 - 338, The goroutine currently
assigns to the outer err variable (err = srv.Serve(lis)), which can create a
data race; change the goroutine to declare a local error variable instead (e.g.,
use err := srv.Serve(lis) or localErr := srv.Serve(lis)) and use that local
variable in the conditional and slogctx.Error call so the outer err is not
mutated; ensure this change is applied inside the anonymous func that calls
srv.Serve(lis) and that slogctx.Error still logs the local error and uses ctx.
internal/business/business.go (1)

58-58: Return a non-nil error if either server returns one.

Current return logic can still mask an abnormal shutdown if the first received value is nil and the second result is non-nil. Prefer selecting a non-nil error across both goroutine results.

♻️ Suggested adjustment
-	err := <-errChan
-	if err != nil {
-		slogctx.Error(ctx, "Shutting down servers", "error", err)
+	firstErr := <-errChan
+	if firstErr != nil {
+		slogctx.Error(ctx, "Shutting down servers", "error", firstErr)
 	}
 	cancel()

 	// wait for all servers to shutdown
 	wg.Wait()

-	return err
+	var secondErr error
+	select {
+	case secondErr = <-errChan:
+	default:
+	}
+	if firstErr != nil {
+		return firstErr
+	}
+	return secondErr
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal/business/business.go` at line 58, The current return statement just
returns err which can mask a non-nil error from the other goroutine; after
collecting both goroutine results (the two error variables you read from
channels, e.g., err and err2 or err1/err2), change the return logic to return
the first non-nil error (for example: if err != nil { return err } return err2)
so a non-nil error from either server is propagated.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@integration/infra_test.go`:
- Around line 57-60: The current length check uses istat.Cfg.HTTP.Address which
includes the "unix://" scheme, so it overestimates the socket path length;
update the check to extract the actual filesystem path (e.g., remove the
"unix://" prefix or parse the URL) from istat.Cfg.HTTP.Address and validate that
the resulting path length is <= 108, then call t.Fatal with the same message if
the path is too long; ensure you reference istat.Cfg.HTTP.Address when making
the extraction and keep the original test behavior otherwise.

---

Nitpick comments:
In `@integration/grpc_test.go`:
- Around line 333-338: The goroutine currently assigns to the outer err variable
(err = srv.Serve(lis)), which can create a data race; change the goroutine to
declare a local error variable instead (e.g., use err := srv.Serve(lis) or
localErr := srv.Serve(lis)) and use that local variable in the conditional and
slogctx.Error call so the outer err is not mutated; ensure this change is
applied inside the anonymous func that calls srv.Serve(lis) and that
slogctx.Error still logs the local error and uses ctx.

In `@integration/session_grpc_test.go`:
- Around line 205-210: The goroutine that calls srv.Serve(lis) reuses the outer
variable err; change it to declare a new scoped variable inside the goroutine
(use err := srv.Serve(lis)) so the error returned by srv.Serve is local to that
goroutine and avoids a potential data race when logging with slogctx.Error;
update the anonymous goroutine block that currently assigns to err to instead
use a short declaration and keep the existing conditional log using the local
err variable.

In `@internal/business/business.go`:
- Line 58: The current return statement just returns err which can mask a
non-nil error from the other goroutine; after collecting both goroutine results
(the two error variables you read from channels, e.g., err and err2 or
err1/err2), change the return logic to return the first non-nil error (for
example: if err != nil { return err } return err2) so a non-nil error from
either server is propagated.

In `@internal/grpc/oidcmapping.go`:
- Around line 103-104: The current branch in RemoveOIDCMapping logs
missing-tenant errors with slogctx.Warn which is noisy for idempotent removals;
change the logic to detect the not-found condition (e.g., errors.Is(err,
ErrNotFound) or comparing with ErrNotFound) and log it at Debug level with
slogctx.Debug (including the same context/error), while retaining slogctx.Warn
for other unexpected errors so only real failures remain at warn level.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: eeea47ca-1602-4c36-992a-5c8b1c0b6222

📥 Commits

Reviewing files that changed from the base of the PR and between 88da356 and af39d5c.

📒 Files selected for processing (13)
  • Makefile
  • cmd/session-manager/main.go
  • integration/api-server-status_test.go
  • integration/api-server_test.go
  • integration/grpc_test.go
  • integration/housekeeper_test.go
  • integration/infra_test.go
  • integration/session_grpc_test.go
  • internal/business/business.go
  • internal/business/business_test.go
  • internal/business/server/http_server.go
  • internal/cmdutils/cmdutils.go
  • internal/grpc/oidcmapping.go

Comment thread integration/infra_test.go
@alienvspredator alienvspredator enabled auto-merge (squash) March 24, 2026 17:03
@alienvspredator alienvspredator merged commit 3d8db87 into main Mar 25, 2026
8 checks passed
@alienvspredator alienvspredator deleted the fix/integration-tests branch March 25, 2026 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working dev-ops test tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants