Skip to content

fix(hc): Adds ID reservations to tombstone tests #89352

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

Merged
merged 3 commits into from
Apr 14, 2025

Conversation

GabeVillalobos
Copy link
Member

@GabeVillalobos GabeVillalobos commented Apr 10, 2025

Tombstone testing currently relies on hardcoded model IDs to ensure correctness when batching and watermarking. This unfortunately leaves the tests susceptible to failing if a hardcoded model ID collides with a model using the primary key sequence.

This addresses this issue by reserving a minimum number of IDs using a new utility function, ensuring we always have the minimum requisite IDs needed to perform our test.

Comment on lines 612 to 614
with assume_test_silo_mode_of(model):
with transaction.atomic(using=router.db_for_write(model)):
with connections[router.db_for_write(model)].cursor() as cursor:
Copy link
Member

Choose a reason for hiding this comment

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

You could combine all of these with , to save some indentation.

Comment on lines +683 to 685
reserve_model_ids(Monitor, 121)
reserve_model_ids(User, 78)
desired_user_and_monitor_ids = [(10, 9), (42, 40), (77, 120)]
Copy link
Member

Choose a reason for hiding this comment

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

I thought part of the problem was that the explict pk values already existed in the database and using the same ids over caused integrity errors. Does this advance the sequences to the point where other tests use higher values?

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't encounter that case when testing. Using @asottile-sentry's script, I was getting PK collisions on newly created monitors without explicit PKs specified, and the PK ID sequence incremented causing it to overlap. I can guard against this case as well by just clearing monitors and users in a setup block.

@GabeVillalobos GabeVillalobos merged commit 285789c into master Apr 14, 2025
57 checks passed
@GabeVillalobos GabeVillalobos deleted the gv/fix-hc-tombstone-testing-fragility branch April 14, 2025 16:43
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