Merged
Conversation
The problem is that there is no way to know if all rows have already been processed by the time `*BatchUpdater.Close()` is called. If they have been, then `numberOfUpdates()` will return 1 less than expected, causing the flakiness. There are two ways to fix this: - Make sure enough time passes between calls to `Increase()` and `Close()`. A call to `runtime.Gosched()` in the test before calling close could also help, but there are no guarantees. Timing-based tests are also generally icky. - Keep track of whether `Close()` actually resulted in any processed rows, and adjust the expected number of updates if so. This has to advantage of working 100% reliably, eliminating the flakiness, at the cost of introducing a field only used for tests. This commit implements the second approach. This fixes cloudquery/cloudquery-issues#2367
erezrokah
reviewed
Oct 28, 2024
|
|
||
| assert.Equal(t, 10000, s.sumOfUpdates(), "total should equal number of updated rows") | ||
| assert.Equal(t, 2, s.numberOfUpdates(), "should only update first time and on close if minimum update duration is set") | ||
| assert.Equal(t, rows, s.sumOfUpdates(), "total should equal number of updated rows") |
Member
There was a problem hiding this comment.
I was thinking we can change the test to something like this:
// Number of updates should be between 1 and 2 depending if when close is called there are remaining rows to update
assert.GreaterOrEqual(t, 1, s.numberOfUpdates())
assert.LessOrEqual(t, 2, s.numberOfUpdates())I think it's ok to test the side effect of the code, doesn't really matter why it's 1 or 2. Now the test logic depends on the correctness of dataOnClose, not a big issue though. So you can take it or leave it
Member
Author
There was a problem hiding this comment.
Will take a note for next time :)
erezrokah
approved these changes
Oct 28, 2024
Member
|
Woops didn't notice the automerge. Anyways I changed the PR title so this change doesn't show up in the change log as it's a non user visible change |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
BEGIN_COMMIT_OVERRIDE
chore: Flaky usage tests
END_COMMIT_OVERRIDE
The problem is that there is no way to know if all rows have already been processed by the time
*BatchUpdater.Close()is called. If they have been, thennumberOfUpdates()will return 1 less than expected, causing the flakiness.There are two ways to fix this:
Increase()andClose(). A call toruntime.Gosched()in the test before calling close could also help, but there are no guarantees. Timing-based tests are also generally icky.Close()actually resulted in any processed rows, and adjust the expected number of updates if so. This has to advantage of working 100% reliably, eliminating the flakiness, at the cost of introducing a field only used for tests.This commit implements the second approach.
This fixes https://github.com/cloudquery/cloudquery-issues/issues/2367