Skip to content

refactor(operator): convert test lifecycle to @TestInstance(PER_CLASS)#8452

Draft
paoloantinori wants to merge 1 commit into
mainfrom
worktree-operator-test-parallel-safety
Draft

refactor(operator): convert test lifecycle to @TestInstance(PER_CLASS)#8452
paoloantinori wants to merge 1 commit into
mainfrom
worktree-operator-test-parallel-safety

Conversation

@paoloantinori

@paoloantinori paoloantinori commented Jul 2, 2026

Copy link
Copy Markdown
Member

Summary

Convert operator integration test infrastructure from static to instance-based lifecycle using JUnit 5 @TestInstance(Lifecycle.PER_CLASS). This is a code quality improvement — not a fix for the -T 1C CI failure.

What Changed

  • ITBase and OLMITBase: add @TestInstance(PER_CLASS), convert 12 static fields to instance fields, convert lifecycle methods to instance methods
  • Pure utility methods (calculateNamespace, createK8sClient, etc.) remain static — they don't access instance state
  • 10 subclasses updated: static @BeforeAll → instance, method references ITBase::this::

What This Does NOT Fix

The -T 1C CI failure (issue #8447) is caused by resource exhaustion, not shared Java state. The Makefile runs -pl controller -am — only ONE module's tests execute. The olm-tests module is not involved. Under -T 1C, 8 parallel Maven threads do Quarkus augmentation + compilation while Minikube pods are also running. The CPU/memory pressure causes pods to start slower, exceeding the 120s awaitility timeout.

The correct fix for the CI failure is the -T1 override in the Makefile (PR #8448, already merged). This refactoring is complementary — it eliminates unnecessary static state as a code quality improvement and a prerequisite for future intra-module test parallelism (if ever needed).

Value of This Change

  1. Code quality: static mutable state in test base classes is an anti-pattern. Instance fields with PER_CLASS lifecycle are cleaner and more explicit about ownership.
  2. Future-proofing: if JUnit 5 parallel test execution within a module is ever enabled, instance fields prevent cross-test contamination.
  3. Documentation: demonstrates the pattern for other Quarkus operator projects considering test parallelism — and honestly documents what it does and doesn't solve.

Status

  • Compiles successfully (./mvnw install -f operator/pom.xml -DskipTests)
  • Code review passed (1 blocker found and fixed: AuthTLSITTest.init() was still static)
  • Functional testing (requires Minikube — CI will validate)

Context

See the Known Issues FAQ in Discussion #8365 for the full analysis, including the corrected root cause (resource exhaustion, not shared memory state).

Convert operator integration tests from static to instance-based
lifecycle using JUnit 5 PER_CLASS. This eliminates shared static state
(client, namespace, app) that prevents parallel module execution.

Changes:
- ITBase and OLMITBase: add @testinstance(PER_CLASS), convert static
  fields to instance fields, convert @BeforeAll/@afterall to instance
  methods
- Pure utility methods (calculateNamespace, createK8sClient, etc.)
  remain static since they don't access instance state
- 10 subclasses updated: static @BeforeAll → instance, method
  references ITBase:: → this::

This is a prerequisite for removing the -T1 override in the operator
Makefile. Cross-module parallel execution also requires namespace-scoped
operator watching (separate change).

Signed-off-by: Paolo Antinori <pantinor@gmail.com>
@paoloantinori paoloantinori added the orchestrator/disabled PR lifecycle orchestrator is disabled for this PR label Jul 2, 2026
@sonarqubecloud

sonarqubecloud Bot commented Jul 2, 2026

Copy link
Copy Markdown

@paoloantinori

Copy link
Copy Markdown
Member Author

Paolo's note:
this is the result of AI chasing another thing, and doing all this work.
I wouldn't call it particularly important if not only for the future-proofing consideration.

I leave you decide the tradeoff between clarity and future proof

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

orchestrator/disabled PR lifecycle orchestrator is disabled for this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant