Skip to content

Conversation

Copy link

Copilot AI commented Oct 30, 2025

Tests spawn background pricing update goroutines that continue running after test completion, causing "Log in goroutine after test has completed" panics.

Changes

pkg/providers/pricing/pricing.go:

  • Add sync.WaitGroup to Provider struct to track the pricing update goroutine
  • Wrap goroutine with wg.Add(1) and defer wg.Done()
  • Add Shutdown() method to wait for goroutine exit

pkg/providers/pricing/suite_test.go:

  • Track all created pricing providers in pricingProviders slice
  • Call Shutdown() on each provider in AfterEach after context cancellation
  • Ensures goroutines fully exit before test completion
// Before: goroutine continues running after test completes
p := pricing.NewProvider(ctx, env, api, region, make(chan struct{}))

// After: goroutine is tracked and cleaned up
p := trackProvider(pricing.NewProvider(ctx, env, api, region, make(chan struct{})))
// AfterEach calls stop() then p.Shutdown() to wait for exit

The Shutdown() method is test-only infrastructure; production code uses long-lived contexts and relies on process termination.

Original prompt

Tests in pkg/providers/pricing/pricing.go spawn a background goroutine (pricing update loop) that is not stopped before the test finishes, resulting in a panic: 'Log in goroutine after TestAzure has completed'.

Fix: Ensure all goroutines started in pricing provider tests are stopped at test completion. This can be done by refactoring test setup to use a context with cancellation and ensuring the goroutine respects context cancellation. Add cleanup logic to the tests in pkg/providers/pricing/suite_test.go so that any background processes are always stopped before the test exits.

Example:

  • Use context.WithCancel in test setup
  • Pass context to the pricing update loop
  • Call cancel() in test teardown/AfterEach
  • Ensure goroutine checks context.Done and exits when cancelled

Apply this fix in pkg/providers/pricing/pricing.go and pkg/providers/pricing/suite_test.go.

Reference code location:

log.FromContext(ctx).V(0).Info("starting pricing update loop")

Only address the goroutine cleanup issue (item 3). Do not modify coverage or file path logic.

This pull request was created as a result of the following prompt from Copilot chat.

Tests in pkg/providers/pricing/pricing.go spawn a background goroutine (pricing update loop) that is not stopped before the test finishes, resulting in a panic: 'Log in goroutine after TestAzure has completed'.

Fix: Ensure all goroutines started in pricing provider tests are stopped at test completion. This can be done by refactoring test setup to use a context with cancellation and ensuring the goroutine respects context cancellation. Add cleanup logic to the tests in pkg/providers/pricing/suite_test.go so that any background processes are always stopped before the test exits.

Example:

  • Use context.WithCancel in test setup
  • Pass context to the pricing update loop
  • Call cancel() in test teardown/AfterEach
  • Ensure goroutine checks context.Done and exits when cancelled

Apply this fix in pkg/providers/pricing/pricing.go and pkg/providers/pricing/suite_test.go.

Reference code location:

log.FromContext(ctx).V(0).Info("starting pricing update loop")

Only address the goroutine cleanup issue (item 3). Do not modify coverage or file path logic.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Fix panic by stopping goroutines in pricing provider tests Fix goroutine leak in pricing provider tests Oct 30, 2025
Copilot AI requested a review from matthchr October 30, 2025 16:45
Copilot finished work on behalf of matthchr October 30, 2025 16:45
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.

2 participants