Skip to content

Replace local context.Background() calls with global context in notebook controller tests #648

@coderabbitai

Description

@coderabbitai

Problem

The notebook controller tests in components/odh-notebook-controller/controllers/notebook_controller_test.go contain 15 instances of local context.Background() calls that should be replaced with the global context defined in suite_test.go.

Current State

  • Tests create individual contexts with ctx := context.Background() in each It block
  • Global context is properly set up in suite_test.go with ctx, cancel = context.WithCancel(context.Background()) in BeforeSuite
  • This creates architectural inconsistency and bypasses proper cancellation capabilities

Benefits of Using Global Context

  1. Proper cancellation support - Global context has context.WithCancel() for cleanup when tests are interrupted
  2. Consistency - All tests use the same context management approach
  3. Resource management - Global context is properly managed in test lifecycle
  4. Performance - Eliminates unnecessary context creation overhead

Scope

Replace all 15 instances of:

It("Should do something", func() {
    ctx := context.Background()
    // test code...
})

With:

It("Should do something", func() {
    // Use global ctx directly
    Expect(cli.Create(ctx, resource)).Should(Succeed())
    // test code...
})

References

Acceptance Criteria

  • Remove all 15 instances of local context.Background() creation
  • Verify all tests use the global ctx variable consistently
  • Ensure test functionality remains unchanged
  • Update any similar patterns in other test files if found

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions