Skip to content

chore(tests): parallelize cmd tests that touch no shared state - #2283

Merged
cristim merged 2 commits into
mainfrom
chore/58-parallel-cmd
Oct 20, 2026
Merged

cristim merged 2 commits into
mainfrom
chore/58-parallel-cmd

Conversation

@cristim

@cristim cristim commented Oct 20, 2026

Copy link
Copy Markdown
Member

Closes #58. This is the cli cmd/ sweep; the go-repo half merged as go#546-#549.

It adds t.Parallel() to 228 of the 523 top-level tests in cmd/ (package main), in one commit: +228, no deletions, 64 files. Subtests are untouched.

Method. A type-aware scanner (go/packages + go/types) walks each test's callees transitively. It reports every write to a package-level var of any package, every call to a global setter, and every package var the test reaches.

  • Before: 0 parallel and 523 sequential; 183 reach a global write.
  • Only write-free tests whose reachable globals are read-only (errors, regexps, CSV tables, fixtures) are parallelized.
  • After: 228 parallel and 295 sequential, and 0 parallel tests reach a global write.

Left sequential on purpose:

  • tests that write globals or swap seams (toolCfg, writeAuditRecordFn, waitBetweenPurchases, shutdownRequested, the *Fn and fetcher seams);
  • anything using rootCmd or the cobra flag vars;
  • tests touching os.Stdout, os.Stderr, os.Stdin or os.Args (including the subprocess re-exec tests);
  • AppLogger users;
  • t.Setenv and t.Chdir users;
  • http.DefaultTransport users.

go test -race -count=1 ./cmd/... passes in two separate runs plus a -shuffle=on run. vet, lint and secrets are clean.

Note: wall time is unchanged at about 120s, because the slowest tests are the sequential HTTP-heavy ones. The benefit is that the safe tests are now explicitly marked, rather than a speed-up.

🤖 Generated with Claude Code

Add t.Parallel() to 228 top-level cmd tests that a type-aware scan shows
reach no package-level var write or global setter, transitively.

Refs #58

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

  • Run on-demand review

This review includes 64 billable files and costs up to $16.00.

  • Ask an admin to make reviews automatic

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Or wait 22 minutes for your next included review.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available. Your 86 included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository: LeanerCloud/cloud-commitments-cli/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: 29048888-21fd-4e2c-a1dd-7f5b6ee5d084
📥 Commits

Reviewing files that changed from the base of the PR and between 699fb4c and 959f00e.

📒 Files selected for processing: 64
  • cmd/archera_comparison_key_test.go
  • cmd/archera_comparison_masking_test.go
  • cmd/archera_comparison_test.go
  • cmd/cancellation_prepurchase_test.go
  • cmd/cancellation_test.go
  • cmd/configure_azure_sp_test.go
  • cmd/configure_azure_store_test.go
  • cmd/configure_gcp_step_test.go
  • cmd/configure_gcp_store_test.go
  • cmd/configure_gcp_test.go
  • cmd/configure_test.go
  • cmd/csv_real_purchase_test.go
  • cmd/effective_dry_run_test.go
  • cmd/helpers_account_alias_test.go
  • cmd/helpers_adjust_existing_test.go
  • cmd/helpers_count_linear_test.go
  • cmd/helpers_instance_limit_rescale_test.go
  • cmd/helpers_instance_limit_test.go
  • cmd/helpers_test.go
  • cmd/helpers_typed_nil_details_test.go
  • cmd/instance_limit_savings_plan_test.go
  • cmd/main_parse_services_test.go
  • cmd/main_purchase_id_comprehensive_test.go
  • cmd/main_purchase_id_test.go
  • cmd/main_service_client_test.go
  • cmd/main_test.go
  • cmd/multi_service_account_names_test.go
  • cmd/multi_service_adjust_excluded_versions_test.go
  • cmd/multi_service_apply_filters_test.go
  • cmd/multi_service_coverage_extended_support_test.go
  • cmd/multi_service_coverage_major_versions_test.go
  • cmd/multi_service_coverage_test.go
  • cmd/multi_service_csv_cap_ranking_test.go
  • cmd/multi_service_csv_coverage_column_test.go
  • cmd/multi_service_csv_formatters_test.go
  • cmd/multi_service_csv_header_test.go
  • cmd/multi_service_csv_report_test.go
  • cmd/multi_service_csv_strict_test.go
  • cmd/multi_service_csv_test.go
  • cmd/multi_service_csv_thresholds_test.go
  • cmd/multi_service_csv_total_row_test.go
  • cmd/multi_service_csv_write_failure_test.go
  • cmd/multi_service_determine_services_test.go
  • cmd/multi_service_engine_versions_paginate_test.go
  • cmd/multi_service_engine_versions_test.go
  • cmd/multi_service_extended_support_unavailable_test.go
  • cmd/multi_service_extract_major_version_test.go
  • cmd/multi_service_filters_savings_plans_test.go
  • cmd/multi_service_filters_test.go
  • cmd/multi_service_helpers_test.go
  • cmd/multi_service_max_instances_test.go
  • cmd/multi_service_rds_instances_pages_test.go
  • cmd/multi_service_should_include_test.go
  • cmd/multi_service_stats_plan_types_test.go
  • cmd/multi_service_stats_test.go
  • cmd/multi_service_test.go
  • cmd/purchase_account_guard_test.go
  • cmd/purchase_failure_exit_2157_test.go
  • cmd/purchase_safeguards_2121_test.go
  • cmd/purchase_succeeded_summaries_2205_test.go
  • cmd/savings_plan_purchase_test.go
  • cmd/savings_plan_region_test.go
  • cmd/secrets_store_test.go
  • cmd/validators_test.go
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@cristim

cristim commented Oct 20, 2026

Copy link
Copy Markdown
Member Author

Review T (independent, claude-cc-libs-rev-T): APPROVE at 77eda67

Method. The go/types scanner, adapted to the cli module and loaded with Tests:true, follows callees across all LeanerCloud packages (pkg/logging, pkg/common, recommendations). It adds two checks: pointer-receiver method calls on globals (the rootCmd.SetArgs class), and every package var each parallel test reaches.

Result. The 228 parallel tests reach:

  • 0 direct global writes (assignments, os.Setenv, logging.SetOutput);
  • only goroutine-safe pointer methods on globals: regexp Match and Replace on archeraQuotedEscapeRE, accountIDPattern, azureUUIDRegex and gcpProjectIDRegex;
  • read-only data, such as the CSV column tables, engine maps, rdsInstanceNU, spTypeServices, fixtures and supportTable, which code only ranges over;
  • none of rootCmd, AppLogger, toolCfg, the *Opts structs, the HTTP clients or any seam func.

go test -race -count=1 ./cmd/... passes.

Limit. The scan does not follow writes through interface calls or function values.

@cristim

cristim commented Oct 20, 2026

Copy link
Copy Markdown
Member Author

Review W (independent, claude-cc-libs-rev-W): APPROVE at 77eda67

  • Diff. 64 files, +228, and every added line is t.Parallel().
  • Race runs. go test -race -count=1 ./cmd/... passes in two separate runs plus one -shuffle=on run, with 0 DATA RACE.
  • Static check. A go/ast tool follows calls for each of the 228 tests. The only package vars they reach are csvDetailColumns, csvThresholdColumns, awsFixtures and errPurchasesFailed, all read-only. Every rootCmd, AppLogger, DefaultTransport, os.Stdout and seam user stays serial. The 228 bodies contain no Setenv, Chdir, ports, os.Stdout/os.Args or exec. AccountAliasCache has its own RWMutex and is built per test.

Notes:

  • cancellation_test.go:267 sends a process-wide SIGINT from a parallel test. It is safe today, but it is being made serial before merge.
  • multi_service_csv_report_test.go writes fixed /tmp/test_*.csv paths. This is pre-existing and tracked as a follow-up (use t.TempDir()).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cristim

cristim commented Oct 20, 2026

Copy link
Copy Markdown
Member Author

Review T (independent, claude-cc-libs-rev-T): APPROVE at 959f00e

git diff 77eda672 959f00e changes only cmd/cancellation_test.go:268: the t.Parallel() in TestInvocationContext_FurtherSigintsAreAbsorbed is replaced by a comment explaining why it stays serial. Nothing else changes.

@cristim

cristim commented Oct 20, 2026

Copy link
Copy Markdown
Member Author

Review W (independent, claude-cc-libs-rev-W): APPROVE at 959f00e

git diff 77eda672 959f00e is exactly one line in cmd/cancellation_test.go: the t.Parallel() in TestInvocationContext_FurtherSigintsAreAbsorbed is replaced by a comment. Nothing else changes. The race runs at 77eda67 passed (two separate runs plus one shuffled), and CI re-runs the race suite on this head.

@cristim

cristim commented Oct 20, 2026

Copy link
Copy Markdown
Member Author

Merge gate verdict (claude-cc-libs)

Every gate holds at head 959f00e:

  • Two independent reviews approve the reviewed head 959f00e. The branch was then updated from main, and the PR diff is byte-identical to the reviewed diff (compared mechanically).
  • CI is green on 959f00e, which is the reviewed change on top of current main.
  • 0 unresolved threads; MERGEABLE/CLEAN.

CodeRabbit is waived as a merge gate under the 2026-10-19 decision. Squash-merging.

@cristim
cristim merged commit f7baf8e into main Oct 20, 2026
12 checks passed
@cristim
cristim deleted the chore/58-parallel-cmd branch October 20, 2026 03:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chore(tests): finish t.Parallel() adoption sweep across remaining packages

1 participant