Skip to content

[Testing] fix flaky tests in verification fetcher chunk consumer#8588

Merged
zhangchiqing merged 1 commit into
masterfrom
leo/fix-flaky-tests
Jun 26, 2026
Merged

[Testing] fix flaky tests in verification fetcher chunk consumer#8588
zhangchiqing merged 1 commit into
masterfrom
leo/fix-flaky-tests

Conversation

@zhangchiqing

@zhangchiqing zhangchiqing commented Jun 25, 2026

Copy link
Copy Markdown
Member

Fix flaky tests TestProduceConsume/pushing_10_receive_10

Summary by CodeRabbit

  • Tests
    • Improved verification coverage for consumer job processing with more reliable completion tracking.
    • Updated the checks for both sequential and concurrent processing scenarios to better confirm all items are handled before assertions run.

@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The consumer verification test updates the sequential and concurrent receive scenarios to coordinate completion with wait groups and mutex-protected slices instead of atomic counters. The test now waits for all queued work to finish before checking consumer completion and asserting collected locators.

Changes

Chunk consumer verification tests

Layer / File(s) Summary
Sequential receive-10 sync
engine/verification/fetcher/chunkconsumer/consumer_test.go
The sequential subtest pre-adds 10 completions and waits for finishAll before waiting on consumer.Done().
Concurrent receive-100 counting
engine/verification/fetcher/chunkconsumer/consumer_test.go
The concurrent subtest removes atomic counting, appends locators under a mutex, calls consumer.Check() after each job, waits for completion, and asserts called has 100 entries.

Estimated review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I hopped through tests with careful grace,
Wait groups lined up in the right place.
No atomics left to keep the score,
Just locked-up calls and checks galore.
When all jobs finish, the bunny cheers!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: stabilizing flaky verification fetcher chunk consumer tests.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch leo/fix-flaky-tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@github-actions

Copy link
Copy Markdown
Contributor

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@zhangchiqing zhangchiqing marked this pull request as ready for review June 25, 2026 18:34
@zhangchiqing zhangchiqing requested a review from a team as a code owner June 25, 2026 18:34

@coderabbitai coderabbitai Bot left a comment

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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
engine/verification/fetcher/chunkconsumer/consumer_test.go (1)

120-126: 🩺 Stability & Availability | 🟠 Major

Require assertions inside goroutines can cause test hangs if errors occur.

In this test, the loop spawns goroutines that call require.NoError and require.True (lines 123–124). If an assertion fails inside a spawned goroutine, the testing.T context does not abort the main test process immediately; instead, the goroutine terminates silently.

This execution path prevents consumer.Check() from running for that specific item (line 125). Since consumer.Check() triggers the callback that calls finishAll.Done(), the finishAll.Wait() on line 129 will wait indefinitely for that missing completion, turning a simple assertion failure into a permanent test hang.

To fix this, defer the assertions to the main test goroutine:

Suggested fix
+			var storeErrs []string
+			var mu sync.Mutex
 			for i := 0; i < len(locators); i++ {
 				go func(i int) {
 					ok, err := chunksQueue.StoreChunkLocator(locators[i])
-					require.NoError(t, err, fmt.Sprintf("chunk locator %v can't be stored", i))
-					require.True(t, ok)
+					if err != nil {
+						mu.Lock()
+						storeErrs = append(storeErrs, fmt.Sprintf("chunk locator %v can't be stored: %v", i, err))
+						mu.Unlock()
+						return
+					}
+					if !ok {
+						mu.Lock()
+						storeErrs = append(storeErrs, fmt.Sprintf("chunk locator %v was not stored", i))
+						mu.Unlock()
+						return
+					}
 					consumer.Check() // notify the consumer
 				}(i)
 			}
+			storeAll.Wait() // Implicitly wait for goroutines to finish if using WaitGroup, otherwise time.Sleep or similar
+
+			// Assert errors back in the main goroutine to fail the test cleanly
+			for _, e := range storeErrs {
+				t.Error(e)
+			}
+
+			// Or use a WaitGroup approach as originally suggested:
+			// var sg sync.WaitGroup
+			// ...
+			// storeErrs := make(chan string, len(locators))
+			// ...
+			// close(storeErrs)
+			// for e := range storeErrs { require.Fail(t, e) }
🤖 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 `@engine/verification/fetcher/chunkconsumer/consumer_test.go` around lines 120
- 126, Move the assertions out of the spawned goroutine in consumer_test.go so a
failed check cannot prevent progress and hang the test. In the loop that
launches the goroutines around StoreChunkLocator and consumer.Check, have the
goroutine only capture the result (and any error) or send it back to the main
test goroutine, then perform require.NoError and require.True from the main test
flow after the goroutines complete. Use the existing consumer.Check and
finishAll synchronization points to keep completion signaling reliable.
🧹 Nitpick comments (1)
engine/verification/fetcher/chunkconsumer/consumer_test.go (1)

132-137: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Assert the locator set, not just the count.

require.Len(t, called, 100) still passes if one locator is processed twice and another is missed. This test now records every locator, so it can validate the concurrent path much more strongly by comparing the collected locators against locators without relying on order.

🤖 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 `@engine/verification/fetcher/chunkconsumer/consumer_test.go` around lines 132
- 137, The test in consumer_test.go only checks the number of processed
callbacks, so it can miss duplicated or skipped locators. Update the assertion
in the chunk consumer test around the called collection to verify the full set
of recorded locators matches locators, using the existing called slice and the
ChunkConsumer/process callback path, rather than relying on require.Len and
order. Keep the concurrency-safe collection logic, but compare contents so every
expected locator is seen exactly once.
🤖 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.

Outside diff comments:
In `@engine/verification/fetcher/chunkconsumer/consumer_test.go`:
- Around line 120-126: Move the assertions out of the spawned goroutine in
consumer_test.go so a failed check cannot prevent progress and hang the test. In
the loop that launches the goroutines around StoreChunkLocator and
consumer.Check, have the goroutine only capture the result (and any error) or
send it back to the main test goroutine, then perform require.NoError and
require.True from the main test flow after the goroutines complete. Use the
existing consumer.Check and finishAll synchronization points to keep completion
signaling reliable.

---

Nitpick comments:
In `@engine/verification/fetcher/chunkconsumer/consumer_test.go`:
- Around line 132-137: The test in consumer_test.go only checks the number of
processed callbacks, so it can miss duplicated or skipped locators. Update the
assertion in the chunk consumer test around the called collection to verify the
full set of recorded locators matches locators, using the existing called slice
and the ChunkConsumer/process callback path, rather than relying on require.Len
and order. Keep the concurrency-safe collection logic, but compare contents so
every expected locator is seen exactly once.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9bf8b2fd-0fad-4224-83d8-ec6110f6c607

📥 Commits

Reviewing files that changed from the base of the PR and between a526bef and 5640841.

📒 Files selected for processing (1)
  • engine/verification/fetcher/chunkconsumer/consumer_test.go

@zhangchiqing zhangchiqing added this pull request to the merge queue Jun 26, 2026
Merged via the queue into master with commit 4c61355 Jun 26, 2026
61 checks passed
@zhangchiqing zhangchiqing deleted the leo/fix-flaky-tests branch June 26, 2026 16:35
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