Skip to content

make the test loop less race'y#22637

Open
Tofel wants to merge 1 commit into
developfrom
fix-flaky-TestLogEventProvider_ScheduleReadJobs
Open

make the test loop less race'y#22637
Tofel wants to merge 1 commit into
developfrom
fix-flaky-TestLogEventProvider_ScheduleReadJobs

Conversation

@Tofel
Copy link
Copy Markdown
Contributor

@Tofel Tofel commented May 26, 2026

Suspect

Race between Go async preemption and the test's default branch. The select could pick default (reads buffer empty), and before p.CurrentPartitionIdx() was called — a function-call safe point — the goroutine could be preempted. During that suspension, scheduleReadJobs fired all 3 ticks (30ms), incrementing currentPartitionIdx to 3 and sending items to reads. On resume, the test loaded partitionIdx = 3, broke immediately, and never ran another select — leaving items in reads unconsumed and got empty.

Fix

Replaced the racy busy-wait default case with a blocking loop that exits only when all expected IDs appear in reads.

@github-actions
Copy link
Copy Markdown
Contributor

✅ No conflicts with other open PRs targeting develop

@cl-sonarqube-production
Copy link
Copy Markdown

@trunk-io
Copy link
Copy Markdown

trunk-io Bot commented May 26, 2026

Static BadgeStatic BadgeStatic BadgeStatic Badge

View Full Report ↗︎Docs

@Tofel Tofel marked this pull request as ready for review May 26, 2026 09:21
Copilot AI review requested due to automatic review settings May 26, 2026 09:22
@Tofel Tofel requested a review from a team as a code owner May 26, 2026 09:22
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Risk Rating: LOW

This PR updates a concurrency-sensitive test loop in TestLogEventProvider_ScheduleReadJobs to avoid a race between a non-blocking select { default: ... } branch and async goroutine preemption, which could previously cause the test to exit early and leave scheduled reads unconsumed.

Changes:

  • Replaced the busy-wait select loop (with default + runtime.Gosched()) with a blocking loop that continues until all expected IDs have been observed.
  • Removed the now-unneeded runtime import from the test file.

Areas requiring scrupulous human review:

  • None beyond confirming this test’s new termination condition matches the intended assertion semantics (it now exits only once all expected IDs are seen, or fails via timeout/context).

@Tofel Tofel requested a review from jmank88 May 26, 2026 12:14
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.

4 participants