Skip to content

test(azure): make cache, compute and managedredis unit tests hermetic - #266

Merged
cristim merged 1 commit into
mainfrom
test/azure-cache-compute-managedredis-hermetic
Oct 6, 2026
Merged

cristim merged 1 commit into
mainfrom
test/azure-cache-compute-managedredis-hermetic

Conversation

@cristim

@cristim cristim commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

Closes #258

Measured with a counting loopback proxy (HTTPS_PROXY set, NO_PROXY empty, go test -short):

package requests before after wall time before after
services/cache 20 0 48s 1.9s
services/compute 16 0 40s 6.3s
services/managedredis 12 0 29s 0.9s

Tests that made the calls and the live client they left un-stubbed:

  • cache (client.go:448 armredis.NewClient / :453 pager): GetValidResourceTypes_Fallback, ValidateOffering_InvalidSKU, ValidateOffering_ValidSKU, ValidateOffering_CaseInsensitive.
  • compute (client.go:626-631 armcompute.NewResourceSKUsClient pager, via fetchSKUCatalogue): GetRecommendations_EmitsBothPaymentVariants, ConvertAzureVMRecommendation_PopulatesAllFields, TestPurchaseBody_SKUAndQuantityStayInMatchingUnits.
  • managedredis (client.go:419-423 armredis.NewClient pager): GetValidResourceTypes_Fallback, ValidateOffering_ValidSKU, ValidateOffering_InvalidSKU.

Fix is test-only: set the existing mock pagers. Each package gets a network_guard_test.go like database's (#257): TestMain points HTTPS_PROXY/HTTP_PROXY at a counting 403 proxy, a counting test pins the previously live path, and TestMain also fails the run if any test reached the proxy. Removing one stub per package makes the run fail with 4 requests reported.

Gates (providers/azure, GOWORK=off): go build, go vet, go test -race -short -mod=readonly ./..., go mod tidy -diff, gocyclo -over 10, misspell -locale US all exit 0.

Summary by CodeRabbit

  • Tests
    • Expanded coverage for Azure cache, managed Redis, and compute workflows, including SKU lookup, offering validation, and recommendation conversion.
    • Added checks that these workflows operate with local test data without making external network requests.
    • Updated fallback-path tests to use explicitly configured empty pagers, improving consistency across test scenarios.

…ainst live calls

Tests that built a client without a SKU pager made live management.azure.com calls (20, 16 and 12 CONNECT attempts, 28-48s per package without network). Inject the existing mock pagers and add the zero-external-requests TestMain guard from the database package; the run fails if any test reaches the proxy.
@cristim cristim added triaged Item has been triaged impact/internal Team-internal only priority/p3 Polish / idea / may never ship severity/low Minor harm urgency/eventually No deadline effort/s Hours type/bug Defect labels Oct 6, 2026
@coderabbitai

coderabbitai Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: LeanerCloud/cloud-commitments-go/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: b8239866-8d7c-497d-bdab-a2d2da863b10
📥 Commits

Reviewing files that changed from the base of the PR and between de5d161 and f237c96.

📒 Files selected for processing (6)
  • providers/azure/services/cache/client_test.go
  • providers/azure/services/cache/network_guard_test.go
  • providers/azure/services/compute/client_test.go
  • providers/azure/services/compute/network_guard_test.go
  • providers/azure/services/managedredis/client_test.go
  • providers/azure/services/managedredis/network_guard_test.go

Included review availability: This review used your included allowance. 0 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 1 review per hour.


📝 Walkthrough

Walkthrough

Tests in the Azure cache, compute, and managedredis packages now stub pagers before SKU and recommendation checks. Each package also adds a proxy-based guard that counts outbound requests and fails successful test runs if requests reach the proxy.

Changes

Azure test network guards

Layer / File(s) Summary
Stub pagers in existing tests
providers/azure/services/cache/client_test.go, providers/azure/services/compute/client_test.go, providers/azure/services/managedredis/client_test.go
Tests set empty pagers before SKU retrieval, offering validation, or recommendation conversion. Existing assertions remain in place.
Count outbound requests in package tests
providers/azure/services/cache/network_guard_test.go, providers/azure/services/compute/network_guard_test.go, providers/azure/services/managedredis/network_guard_test.go
Each package configures a proxy that counts and rejects requests. Added tests exercise client operations with stub pagers and assert that the request count does not increase.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Other · Severity of issue fixed: Low

Merge Risk: ⚪ Minimal · up to f237c

The changed tests retain API-error fallback coverage, and no concrete issue requiring a fix before merge was established.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 37.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 16 functions across 6 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the changes: making Azure cache, compute, and managedredis unit tests hermetic.
Linked Issues check ✅ Passed Issue #258 requires identifying the leaking tests, stubbing live clients or pagers, and adding a zero-transport-attempt regression check in cache, compute, and managedredis. The PR adds pager stubs to…
Out of Scope Changes check ✅ Passed The reported changes are limited to test pager setup and network regression guards in the three packages named by issue #258. These changes directly implement the issue objectives. No unrelated change…
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@cristim
cristim merged commit ef079e3 into main Oct 6, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/s Hours impact/internal Team-internal only priority/p3 Polish / idea / may never ship severity/low Minor harm triaged Item has been triaged type/bug Defect urgency/eventually No deadline

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test(azure): cache, compute and managedredis unit tests still make live management.azure.com calls

1 participant