Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some flakey tests #851

Merged
merged 6 commits into from
Nov 5, 2024
Merged

Fix some flakey tests #851

merged 6 commits into from
Nov 5, 2024

Conversation

michelletran-codecov
Copy link
Contributor

@michelletran-codecov michelletran-codecov commented Nov 4, 2024

Extracted this from #729

A few of the tests become flaky when migrating to the Django models because of some unique references that's defined in Django, but not SQLAlchemy.

In particular, the way that FactoryBoy creates references can be flakey (i.e. Commits referencing Pulls. If the original pull is not flushed, there is a chance that the commit gets created first, which inadvertently creates a separate pull with the id of the one that you specified to create). So, doing an explicit flush will of pull before creating the commit will fix this.

Also fixed a test where DB returned results are not necessarily ordered.

Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. In 2022 this entity acquired Codecov and as result Sentry is going to need some rights from me in order to utilize my contributions in this PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.

Copy link

codecov bot commented Nov 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.02%. Comparing base (8fec23c) to head (1adff7e).
Report is 5 commits behind head on main.

✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #851   +/-   ##
=======================================
  Coverage   98.02%   98.02%           
=======================================
  Files         444      444           
  Lines       36003    36016   +13     
=======================================
+ Hits        35292    35305   +13     
  Misses        711      711           
Flag Coverage Δ
integration 98.02% <100.00%> (+<0.01%) ⬆️
unit 98.02% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
NonTestCode 95.97% <ø> (+<0.01%) ⬆️
OutsideTasks 98.05% <ø> (+<0.01%) ⬆️
Files with missing lines Coverage Δ
tasks/tests/integration/test_upload_e2e.py 100.00% <100.00%> (ø)
tasks/tests/unit/test_manual_trigger.py 97.50% <100.00%> (+0.20%) ⬆️
...sks/tests/unit/test_test_results_processor_task.py 100.00% <100.00%> (ø)
tasks/tests/unit/test_upload_finisher_task.py 100.00% <100.00%> (ø)

... and 6 files with indirect coverage changes

@codecov-notifications
Copy link

codecov-notifications bot commented Nov 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #851   +/-   ##
=======================================
  Coverage   98.02%   98.02%           
=======================================
  Files         444      444           
  Lines       36003    36016   +13     
=======================================
+ Hits        35292    35305   +13     
  Misses        711      711           
Flag Coverage Δ
integration 98.02% <100.00%> (+<0.01%) ⬆️
unit 98.02% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
NonTestCode 95.97% <ø> (+<0.01%) ⬆️
OutsideTasks 98.05% <ø> (+<0.01%) ⬆️
Files with missing lines Coverage Δ
tasks/tests/integration/test_upload_e2e.py 100.00% <100.00%> (ø)
tasks/tests/unit/test_manual_trigger.py 97.50% <100.00%> (+0.20%) ⬆️
...sks/tests/unit/test_test_results_processor_task.py 100.00% <100.00%> (ø)
tasks/tests/unit/test_upload_finisher_task.py 100.00% <100.00%> (ø)

... and 6 files with indirect coverage changes

@codecov-qa
Copy link

codecov-qa bot commented Nov 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.02%. Comparing base (8fec23c) to head (1adff7e).
Report is 5 commits behind head on main.

✅ All tests successful. No failed tests found.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #851   +/-   ##
=======================================
  Coverage   98.02%   98.02%           
=======================================
  Files         444      444           
  Lines       36003    36016   +13     
=======================================
+ Hits        35292    35305   +13     
  Misses        711      711           
Flag Coverage Δ
integration 98.02% <100.00%> (+<0.01%) ⬆️
unit 98.02% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
NonTestCode 95.97% <ø> (+<0.01%) ⬆️
OutsideTasks 98.05% <ø> (+<0.01%) ⬆️
Files with missing lines Coverage Δ
tasks/tests/integration/test_upload_e2e.py 100.00% <100.00%> (ø)
tasks/tests/unit/test_manual_trigger.py 97.50% <100.00%> (+0.20%) ⬆️
...sks/tests/unit/test_test_results_processor_task.py 100.00% <100.00%> (ø)
tasks/tests/unit/test_upload_finisher_task.py 100.00% <100.00%> (ø)

... and 6 files with indirect coverage changes

Copy link

codecov-public-qa bot commented Nov 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.02%. Comparing base (8fec23c) to head (1adff7e).
Report is 4 commits behind head on main.

✅ All tests successful. No failed tests found.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #851   +/-   ##
=======================================
  Coverage   98.02%   98.02%           
=======================================
  Files         444      444           
  Lines       36003    36016   +13     
=======================================
+ Hits        35292    35305   +13     
  Misses        711      711           
Flag Coverage Δ
integration 98.02% <100.00%> (+<0.01%) ⬆️
unit 98.02% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
NonTestCode 95.97% <ø> (+<0.01%) ⬆️
OutsideTasks 98.05% <ø> (+<0.01%) ⬆️
Files Coverage Δ
tasks/tests/integration/test_upload_e2e.py 100.00% <100.00%> (ø)
tasks/tests/unit/test_manual_trigger.py 97.50% <100.00%> (+0.20%) ⬆️
...sks/tests/unit/test_test_results_processor_task.py 100.00% <100.00%> (ø)
tasks/tests/unit/test_upload_finisher_task.py 100.00% <100.00%> (ø)

... and 6 files with indirect coverage changes

@michelletran-codecov michelletran-codecov marked this pull request as ready for review November 4, 2024 16:34
@michelletran-codecov michelletran-codecov requested a review from a team November 4, 2024 16:34
Comment on lines 528 to 530
# assert that test_flag_bridges is a subset of tests
assert set(bridge.test_id for bridge in test_flag_bridges).issubset(
set(x.id for x in tests)
)
Copy link
Contributor

Choose a reason for hiding this comment

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

previously this was testing for equality, not a subset relation. is this really what we want?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, good point, the subset test doesn't really make sense. We might actually want to check that the test_ids in test_flag_bridge match the ones in test_instances (non-failure, I'm guessing). The flakiness with this test is that it assumes ordering of tests, where we should not have that assumption.

Since I'm having to guess the intent of this check, I can also be convince that this test isn't super useful, and just remove it. I'm leaning towards just modifying it to match the ids in test_instance out of conservatism.

This is fragile because hard-coding the pullid is more likely to run into conflicts
The first flush to create the commit wit pullid=12 actually creates it,
but then it gets added again later. This just avoids flushing multiple times
and attempts to create the pull first.
This avoids any other factories that might potentially use the pull object
from recreating it in the database
Flushing the pull before creating the commit seems to reduce the chance of
id collision. This is probably because commit _tries_ to create a pull.
Flushing the pull logs the pull object in the DB, which disables the
CommitFactory from also creating the pull object. This is my best understanding.
@michelletran-codecov michelletran-codecov added this pull request to the merge queue Nov 5, 2024
Merged via the queue into main with commit bf934d6 Nov 5, 2024
26 of 27 checks passed
@michelletran-codecov michelletran-codecov deleted the fix_some_flakey_tests branch November 5, 2024 16:23
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.

2 participants