Conversation
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
📝 WalkthroughWalkthroughTest synchronization improvements were added to Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
module/epochs/epoch_lookup_test.go (2)
225-236:⚠️ Potential issue | 🟡 MinorSame race condition exists here — apply the
throwCalledfix consistently.This subtest has the identical pattern:
Throwcarries assertions, yet theEventuallyonly gates onlen(suite.lookup.epochEvents) == 0. The event can be dequeued from the channel beforeThrowis invoked, so theEventuallycan succeed without theThrowassertions ever running — exactly the flake fixed in the third subtest.Proposed fix
+ throwCalled := make(chan struct{}) ctx.On("Throw", mock.AnythingOfType("*errors.errorString")).Run(func(args mock.Arguments) { err, ok := args.Get(0).(error) assert.True(suite.T(), ok) assert.Contains(suite.T(), err.Error(), fmt.Sprintf(invalidExtensionFinalView, suite.currEpoch.finalView, extension.FinalView)) + close(throwCalled) }) suite.lookup.EpochExtended(suite.currEpoch.epochCounter, nil, extension) // wait for the protocol event to be processed (async) assert.Eventually(suite.T(), func() bool { - return len(suite.lookup.epochEvents) == 0 + select { + case <-throwCalled: + return len(suite.lookup.epochEvents) == 0 + default: + return false + } }, 2*time.Second, 50*time.Millisecond)
244-258:⚠️ Potential issue | 🟡 MinorSame race condition in the second subtest — needs the same synchronization.
Identical to the first subtest:
Throwmock contains assertions butEventuallyonly checks the queue length, so the test can pass withoutThrowever firing.Proposed fix
+ throwCalled := make(chan struct{}) ctx.On("Throw", mock.AnythingOfType("*errors.errorString")).Run(func(args mock.Arguments) { err, ok := args.Get(0).(error) assert.True(suite.T(), ok) assert.Contains(suite.T(), err.Error(), fmt.Sprintf(mismatchEpochCounter, suite.currEpoch.epochCounter, unknownCounter)) + close(throwCalled) }) suite.lookup.EpochExtended(unknownCounter, nil, flow.EpochExtension{ FirstView: suite.currEpoch.finalView + 1, FinalView: suite.currEpoch.finalView + 100, }) // wait for the protocol event to be processed (async) assert.Eventually(suite.T(), func() bool { - return len(suite.lookup.epochEvents) == 0 + select { + case <-throwCalled: + return len(suite.lookup.epochEvents) == 0 + default: + return false + } }, 2*time.Second, 50*time.Millisecond)
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
It should wait for the Throw to happen before trying to assert the epoch events len.
Summary by CodeRabbit