Skip to content

CNTRLPLANE-3237: Add inParallel helper for running encryption test steps concurrently#2352

Merged
openshift-merge-bot[bot] merged 1 commit into
openshift:masterfrom
p0lyn0mial:add-inparallel-helper
Jul 9, 2026
Merged

CNTRLPLANE-3237: Add inParallel helper for running encryption test steps concurrently#2352
openshift-merge-bot[bot] merged 1 commit into
openshift:masterfrom
p0lyn0mial:add-inparallel-helper

Conversation

@p0lyn0mial

@p0lyn0mial p0lyn0mial commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

could be used as a more generic mechanism to run arbitrary scenarios for #2349

Summary by CodeRabbit

  • Tests
    • Added new unit tests covering the parallel execution behavior of encryption test steps.
    • Improved validation of composed step naming and failure handling (including panics and immediate failure).
    • Added a concurrency timing check to confirm multiple steps run concurrently rather than sequentially.

@p0lyn0mial p0lyn0mial requested a review from gangwgr July 8, 2026 12:44
@openshift-ci openshift-ci Bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 8, 2026
@openshift-ci

openshift-ci Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Walkthrough

Adds a new inParallel helper for running test steps concurrently with panic recovery and combined naming, plus tests that validate naming, failure recording, completion counts, and execution timing.

Changes

Parallel test helper

Layer / File(s) Summary
Helper implementation
test/library/encryption/helpers.go
Adds sync support and inParallel(steps ...testStep) testStep, which joins step names, runs each step in its own goroutine, waits with sync.WaitGroup, and reports panics with t.Errorf.
Helper tests
test/library/encryption/helpers_test.go
Adds test helpers for recording failures and counting completions, then validates inParallel naming, panic and FailNow handling, completion counts, and concurrent runtime.

Estimated code review effort: 2 (Simple) | ~12 minutes

🚥 Pre-merge checks | ✅ 15
✅ Passed checks (15 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Stable And Deterministic Test Names ✅ Passed All added test titles are static literals; inParallel only joins step names, and the new tests use fixed t.Run names with no generated values.
Test Structure And Quality ✅ Passed PASS: These are plain Go unit tests, not Ginkgo specs; they’re focused, bounded, and use explicit expected/actual failure messages.
Microshift Test Compatibility ✅ Passed PASS: The PR only adds a concurrency helper and standard Go unit tests; no Ginkgo e2e tests or MicroShift-unsupported OpenShift API usage were added.
Single Node Openshift (Sno) Test Compatibility ✅ Passed The PR adds only Go unit tests and a parallel helper; no Ginkgo e2e tests or multi-node/SNO assumptions are present.
Topology-Aware Scheduling Compatibility ✅ Passed Only test helper/tests in test/library/encryption changed; no deployment manifests, operator code, or controllers were modified, so no scheduling constraints were introduced.
Ote Binary Stdout Contract ✅ Passed Changed files only add a concurrent helper and tests; no main/init/suite-level stdout writes were introduced.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed The added tests are plain Go unit tests; they use no Ginkgo e2e constructs, hardcoded IPs, or external connectivity.
No-Weak-Crypto ✅ Passed No weak crypto, custom crypto, or secret/token comparisons were added; the PR only adds a parallel test-step helper and tests.
Container-Privileges ✅ Passed PR only changes Go helper/tests; no container/K8s manifests or privilege settings (privileged, hostPID/Network/IPC, SYS_ADMIN, allowPrivilegeEscalation) are added.
No-Sensitive-Data-In-Logs ✅ Passed No new logs contain secrets/PII; added panic/error messages only include step names and generic test text.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding an inParallel helper to run encryption test steps concurrently.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@openshift-ci openshift-ci Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 8, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
test/library/encryption/helpers.go (1)

485-509: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

No cancellation/timeout for hung steps.

If one step blocks indefinitely (e.g. a network call in an encryption test), wg.Wait() will block forever, relying solely on the global go test -timeout to eventually abort. Consider threading a context.Context (with a deadline) through testStep so hung steps can be detected/cancelled independently.

As per path instructions, "context.Context for cancellation and timeouts" is expected for Go code in this area.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/library/encryption/helpers.go` around lines 485 - 509, The inParallel
helper can hang forever because it only waits on a WaitGroup and has no per-step
cancellation or timeout handling. Update the testStep flow used by inParallel to
thread a context.Context with a deadline through the testFunc path, and ensure
each step can observe cancellation so a blocked step can be detected and aborted
independently. Keep the fix localized around inParallel and the
testStep/testFunc contract so hung encryption test steps don’t rely solely on
the global test timeout.

Source: Path instructions

test/library/encryption/helpers_test.go (1)

119-133: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Timing-based assertion risks flakiness in CI.

Asserting elapsed < 1s for three 500ms sleeps run in parallel is a reasonable 2x margin locally, but under loaded/throttled CI runners (or low GOMAXPROCS) this can flake. Consider asserting on completed/goroutine-count evidence of concurrency instead of, or in addition to, wall-clock timing, or use a looser/relative threshold.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/library/encryption/helpers_test.go` around lines 119 - 133, The
concurrency test in TestInParallelRunsConcurrently relies on a strict wall-clock
threshold, which can be flaky under slow or heavily loaded CI. Update the test
to validate concurrency using more deterministic evidence from
inParallel/testStep behavior, such as completion ordering or a shared
signal/counter, and if timing remains, loosen it to a relative threshold. Use
the existing TestInParallelRunsConcurrently and inParallel identifiers to locate
the assertion.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@test/library/encryption/helpers.go`:
- Around line 480-509: The inParallel helper does not preserve the
FailNow/require stop-immediately behavior because each step runs inside a wg.Go
goroutine in test/library/encryption/helpers.go. Update inParallel so the
combined testFunc checks whether any step failed after wg.Wait() and then
triggers a real FailNow from the caller goroutine (where supported), and adjust
the comment on inParallel/testStep to reflect that require/t.Fatal in parallel
steps only fails that goroutine unless explicitly propagated.

---

Nitpick comments:
In `@test/library/encryption/helpers_test.go`:
- Around line 119-133: The concurrency test in TestInParallelRunsConcurrently
relies on a strict wall-clock threshold, which can be flaky under slow or
heavily loaded CI. Update the test to validate concurrency using more
deterministic evidence from inParallel/testStep behavior, such as completion
ordering or a shared signal/counter, and if timing remains, loosen it to a
relative threshold. Use the existing TestInParallelRunsConcurrently and
inParallel identifiers to locate the assertion.

In `@test/library/encryption/helpers.go`:
- Around line 485-509: The inParallel helper can hang forever because it only
waits on a WaitGroup and has no per-step cancellation or timeout handling.
Update the testStep flow used by inParallel to thread a context.Context with a
deadline through the testFunc path, and ensure each step can observe
cancellation so a blocked step can be detected and aborted independently. Keep
the fix localized around inParallel and the testStep/testFunc contract so hung
encryption test steps don’t rely solely on the global test timeout.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 57516a8f-b999-4c41-af9c-9da41e8b2aa4

📥 Commits

Reviewing files that changed from the base of the PR and between aa59c3f and 82af32a.

📒 Files selected for processing (2)
  • test/library/encryption/helpers.go
  • test/library/encryption/helpers_test.go

Comment thread test/library/encryption/helpers.go
@p0lyn0mial p0lyn0mial marked this pull request as ready for review July 9, 2026 09:37
@openshift-ci openshift-ci Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 9, 2026
@openshift-ci openshift-ci Bot requested review from ardaguclu and dgrisonnet July 9, 2026 09:37
@@ -0,0 +1,133 @@
package encryption

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need this file ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. I would prefer having tests that ensure errors from individual runs will be reported and propagated to the caller.

Comment thread test/library/encryption/helpers_test.go Outdated
wrapped := make([]testStep, len(steps))
for i, s := range steps {
orig := s.testFunc
wrapped[i] = testStep{name: s.name, testFunc: func(t testing.TB) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of closing over the loop variable, can we consider passing s.testFunc into the closure.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pushed, see if you like it.

if rec.Failed() != tt.expectFailed {
t.Errorf("expected Failed()=%v, actual %v", tt.expectFailed, rec.Failed())
}
if actual := completed.Load(); actual != tt.expectCompleted {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checking completed.Load() immediately may not give goroutines enough time to complete.
can we add small grace time here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that wg.Wait() guarantees all goroutines will finish before inParallel returns.
Does it make sense ?

@p0lyn0mial p0lyn0mial force-pushed the add-inparallel-helper branch from 82af32a to d318a48 Compare July 9, 2026 11:38
@gangwgr

gangwgr commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

/lgtm

@openshift-ci openshift-ci Bot added the lgtm Indicates that a PR is ready to be merged. label Jul 9, 2026
@openshift-ci

openshift-ci Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: gangwgr, p0lyn0mial

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci

openshift-ci Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

@p0lyn0mial: all tests passed!

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@p0lyn0mial p0lyn0mial changed the title Add inParallel helper for running encryption test steps concurrently CNTRLPLANE-3237: Add inParallel helper for running encryption test steps concurrently Jul 9, 2026
@openshift-ci-robot

openshift-ci-robot commented Jul 9, 2026

Copy link
Copy Markdown

@p0lyn0mial: This pull request references CNTRLPLANE-3237 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "5.0.0" version, but no target version was set.

Details

In response to this:

could be used as a more generic mechanism to run arbitrary scenarios for #2349

Summary by CodeRabbit

  • Tests
  • Added new unit tests covering the parallel execution behavior of encryption test steps.
  • Improved validation of composed step naming and failure handling (including panics and immediate failure).
  • Added a concurrency timing check to confirm multiple steps run concurrently rather than sequentially.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Jul 9, 2026
@openshift-merge-bot openshift-merge-bot Bot merged commit 64c3ee5 into openshift:master Jul 9, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. lgtm Indicates that a PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants