Skip to content

chore: Flaky usage tests#1947

Merged
kodiakhq[bot] merged 1 commit intomainfrom
fix/flaky_usage_test
Oct 28, 2024
Merged

chore: Flaky usage tests#1947
kodiakhq[bot] merged 1 commit intomainfrom
fix/flaky_usage_test

Conversation

@dcelasun
Copy link
Copy Markdown
Member

@dcelasun dcelasun commented Oct 28, 2024

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, 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 https://github.com/cloudquery/cloudquery-issues/issues/2367

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
@dcelasun dcelasun requested review from a team, erezrokah and marianogappa October 28, 2024 08:30
@github-actions github-actions bot added the fix label 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")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Will take a note for next time :)

@kodiakhq kodiakhq bot merged commit 3ed75f5 into main Oct 28, 2024
@kodiakhq kodiakhq bot deleted the fix/flaky_usage_test branch October 28, 2024 08:51
@erezrokah erezrokah changed the title fix: Flaky usage tests chore: Flaky usage tests Oct 28, 2024
@erezrokah
Copy link
Copy Markdown
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants