test: reduce unit test runtime by fixing slow polling and real HTTP calls
What does this MR do and why?
Addresses several root causes of slow unit tests identified through profiling and CI pipeline history analysis.
Changes
internal/commands/ci/ciutils/utils.go
- Add
PollInterval time.DurationtoJobOptions. When zero,runTracedefaults to the existing 3-second interval. This lets tests passtime.Millisecondto avoid waiting for the first ticker tick on every test case.
internal/commands/ci/ciutils/utils_test.go
- Add
t.Parallel()toTestTraceJobandTestGetJobId(top-level and subtests) — these only use mock clients with no shared global state. - Pass
PollInterval: time.MillisecondinTestTraceJob'sJobOptions.
internal/commands/auth/login/helper_test.go
- The
"failed to refresh"test case hadtestOAuth2: truebut noapiResponse, so the OAuth token refresh made a real TCP connection togitlab.example.com. In CI (no external network), this blocked on the OS TCP timeout (1–3 minutes). Fix: provide a mock transport that immediately returns"connection refused".
internal/cmdutils/cmdutils_test.go
- Add
t.Parallel()toTest_PickMetadata(top-level and subtests) — no shared global state.
Why not more?
Stack and internal/git tests were considered but cannot be safely parallelized: they call InitGitRepo/InitGitRepoWithCommit which use t.Chdir → os.Chdir, a process-global operation. Parallel subtests would race on the working directory.
Test_UsersPrompt and labels prompt tests reassign package-level function variables (listProjectMembers, listLabels) before running subtests; parallelizing them would create data races.
TestCiTrace (in ci/trace) still takes ~3s because NewCmdTrace's RunE constructs JobOptions internally with no injection point for PollInterval. Since those subtests already run in parallel the effective CI cost is ~3s, which is acceptable without a larger refactor.
MR acceptance checklist
- This MR does not add new product functionality
- Existing unit tests pass
- No documentation changes needed