Improve test robustness#20248
Merged
alice-i-cecile merged 6 commits intobevyengine:mainfrom Jul 23, 2025
Merged
Conversation
alice-i-cecile
approved these changes
Jul 22, 2025
alice-i-cecile
requested changes
Jul 22, 2025
crates/bevy_ecs/src/world/mod.rs
Outdated
| // SAFETY: `&self` gives read access to the entire world. | ||
| unsafe { EntityRef::new(cell) } | ||
| }) | ||
| .filter(|e| !e.contains::<Internal>()) |
Member
There was a problem hiding this comment.
Actually, let's leave this change out of this PR.
chescock
approved these changes
Jul 23, 2025
| assert_eq!(world.query::<&A>().query(&world).count(), 1); | ||
| assert_eq!( | ||
| world | ||
| .query_filtered::<&Observer, Allows<Internal>>() |
Contributor
There was a problem hiding this comment.
Huh, it's unfortunate that we need Allows<Internal> in order to query Observer. As a follow-up, we may want to consider expanding the rule for allowing filters to account for required components so that mentioning Observer disables the Internal filter. I don't know whether it's possible to do that efficiently, though.
alice-i-cecile
approved these changes
Jul 23, 2025
11 tasks
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.
Objective
Many tests currently check against
entity_count()in order to see if the absolute number of entities are where they expect it to be. This is not a very robust of doing it, as we're adding more internal entities (#20204).Solution
Replace
entity_count()by a relevant query. We also changeiter_entitiesto filter out Internal entities by default. I don't know if this is the right approach, because unlike default query filters, there are very few escape hatches for users who do want to iterate through all entities, including the internal ones.I guess you could just make a query.
Actually, why isn't
iter_entitiesjust a query?Testing
I added a
world.spawn(Internal)during world bootstrap and most tests succeeded still.