chore(tests): parallelize pkg/config tests (partial — t.Setenv users stay serial) by cristim · Pull Request #175 · LeanerCloud/cloud-commitments-cli · GitHub
Skip to content

chore(tests): parallelize pkg/config tests (partial — t.Setenv users stay serial) - #175

Merged
cristim merged 2 commits into
feat/multicloud-web-frontendfrom
chore/tparallel-pkg-config
May 6, 2026
Merged

cristim merged 2 commits into
feat/multicloud-web-frontendfrom
chore/tparallel-pkg-config

Conversation

@cristim

@cristim cristim commented Apr 28, 2026 •

Copy link
Copy Markdown
Member

Summary

Continues the t.Parallel() adoption sweep from #58. This PR targets pkg/config/ and uses the standard Go testing mixed-mode pattern: 10 pure tests are parallelised, while 8 tests that mutate process-wide state (t.Setenv / os.Chdir) intentionally remain serial — Go's t.Setenv panics if combined with t.Parallel(), so making them parallel is not a "fix" but a regression.

To prevent future contributors from accidentally adding t.Parallel() to the serial tests, each one carries an inline // NOT parallel: ... comment explaining why.

Per-test classification

Parallel (10) — pure, no env/chdir/global mutation:

  • TestLoad_Defaults
  • TestLoad_ExplicitMissingFile_Error
  • TestLoad_YAMLFile
  • TestLoad_InvalidYAML_Error
  • TestLoad_DryRunAndPurchaseConflict
  • TestLoad_PurchaseFlagSetsDryRunFalse
  • TestLoad_UnknownCloud_Error
  • TestLoad_NegativeThreshold_Error
  • TestValidate_EmptyEnabledClouds_Error
  • TestLoad_YAMLRoundtrip

Serial (8) — documented in-source:

  • TestLoad_MissingDefaultFile_NoError — os.Chdir
  • TestLoad_EnvOverridesYAML — t.Setenv
  • TestLoad_EnvVars — t.Setenv (×11)
  • TestLoad_InvalidEnvVar_Error — t.Setenv
  • TestLoad_InvalidDurationEnvVar_Error — t.Setenv
  • TestLoad_FlagOverridesEnvAndYAML — t.Setenv
  • TestLoad_CUDLYCONFIGEnv — t.Setenv
  • TestLoad_ArgPathTakesPrecedenceOverCUDLYCONFIG — t.Setenv

Out of scope

Test plan

  • cd pkg && go test -race -count=2 ./config/... passes cleanly twice locally
  • All pre-commit hooks pass (gosec, trivy, complexity, full Go tests)
  • CI green on PR

Refs #58

Summary by CodeRabbit

  • Chores
    • Internal test infrastructure optimizations with no impact on user-facing functionality.

@coderabbitai

coderabbitai Bot commented Apr 28, 2026 •

Copy link
Copy Markdown
Contributor

@cristim

cristim commented Apr 28, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Apr 28, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@cristim

cristim commented Apr 28, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Apr 28, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
pkg/config/config_test.go (1)

58-60: Handle working-directory setup/teardown errors explicitly.

Line 58 and Line 60 currently ignore errors; if either fails, the test can leak state or mask root cause.

Suggested hardening
-	orig, _ := os.Getwd()
+	orig, err := os.Getwd()
+	require.NoError(t, err)
 	require.NoError(t, os.Chdir(dir))
-	t.Cleanup(func() { os.Chdir(orig) })
+	t.Cleanup(func() { require.NoError(t, os.Chdir(orig)) })
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/config/config_test.go` around lines 58 - 60, The test currently ignores
errors from os.Getwd() and the cleanup os.Chdir(orig); update the setup to check
and fail the test on error (use require.NoError or t.Fatalf) for os.Getwd() and
the initial os.Chdir(dir), and change the t.Cleanup closure to capture and
handle the error returned by os.Chdir(orig) (call require.NoError or log/fatal
inside the closure) so any failure to restore the working directory is surfaced;
reference the os.Getwd, os.Chdir and t.Cleanup calls in
pkg/config/config_test.go when making these changes.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@pkg/config/config_test.go`:
- Around line 58-60: The test currently ignores errors from os.Getwd() and the
cleanup os.Chdir(orig); update the setup to check and fail the test on error
(use require.NoError or t.Fatalf) for os.Getwd() and the initial os.Chdir(dir),
and change the t.Cleanup closure to capture and handle the error returned by
os.Chdir(orig) (call require.NoError or log/fatal inside the closure) so any
failure to restore the working directory is surfaced; reference the os.Getwd,
os.Chdir and t.Cleanup calls in pkg/config/config_test.go when making these
changes.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ebd45a01-ad3d-4d0c-aed3-b9a00c0d8cda

📥 Commits

Reviewing files that changed from the base of the PR and between 3e655cb and 1dd7b9a.

📒 Files selected for processing (1)
  • pkg/config/config_test.go

cristim added a commit that referenced this pull request Apr 28, 2026
Per CodeRabbit nitpick on PR #175: TestLoad_MissingDefaultFile_NoError
ignored errors from os.Getwd() and the t.Cleanup os.Chdir(orig). If
either fails the test could leak working-directory state into other
tests or mask the root cause of a failure. Wrap both in require.NoError.
@cristim cristim added triaged Item has been triaged priority/p3 Polish / idea / may never ship severity/low Minor harm urgency/eventually No deadline impact/internal Team-internal only effort/xs Trivial / one-liner type/chore Maintenance / non-user-visible labels Apr 28, 2026
cristim added 2 commits April 30, 2026 00:49
…stay serial)

Per-test classification (10 parallel + 8 documented-serial):

Parallel (10) — pure, no env/chdir/global mutation:
- TestLoad_Defaults
- TestLoad_ExplicitMissingFile_Error
- TestLoad_YAMLFile
- TestLoad_InvalidYAML_Error
- TestLoad_DryRunAndPurchaseConflict
- TestLoad_PurchaseFlagSetsDryRunFalse
- TestLoad_UnknownCloud_Error
- TestLoad_NegativeThreshold_Error
- TestValidate_EmptyEnabledClouds_Error
- TestLoad_YAMLRoundtrip

Serial (8) — Go's t.Setenv / os.Chdir mutate process-wide state and
panic if combined with t.Parallel(). Each gets an inline NOT-parallel
comment so future contributors don't accidentally add t.Parallel():
- TestLoad_MissingDefaultFile_NoError (os.Chdir)
- TestLoad_EnvOverridesYAML (t.Setenv)
- TestLoad_EnvVars (t.Setenv x11)
- TestLoad_InvalidEnvVar_Error (t.Setenv)
- TestLoad_InvalidDurationEnvVar_Error (t.Setenv)
- TestLoad_FlagOverridesEnvAndYAML (t.Setenv)
- TestLoad_CUDLYCONFIGEnv (t.Setenv)
- TestLoad_ArgPathTakesPrecedenceOverCUDLYCONFIG (t.Setenv)

Verified: `go test -race -count=2 ./config/...` (from pkg/) passes
cleanly twice.

Refs #58
Per CodeRabbit nitpick on PR #175: TestLoad_MissingDefaultFile_NoError
ignored errors from os.Getwd() and the t.Cleanup os.Chdir(orig). If
either fails the test could leak working-directory state into other
tests or mask the root cause of a failure. Wrap both in require.NoError.
@cristim
cristim force-pushed the chore/tparallel-pkg-config branch from e33cbcf to e963008 Compare April 29, 2026 22:50
@cristim

cristim commented Apr 29, 2026

Copy link
Copy Markdown
Member Author

Rebased onto current feat/multicloud-web-frontend to bring CR review current. @coderabbitai review

@coderabbitai

coderabbitai Bot commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

@cristim
cristim merged commit c13433d into feat/multicloud-web-frontend May 6, 2026
4 checks passed
@cristim
cristim deleted the chore/tparallel-pkg-config branch May 6, 2026 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/xs Trivial / one-liner impact/internal Team-internal only priority/p3 Polish / idea / may never ship severity/low Minor harm triaged Item has been triaged type/chore Maintenance / non-user-visible urgency/eventually No deadline

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant