-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Improve test robustness #20248
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
Improve test robustness #20248
Conversation
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>()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, let's leave this change out of this PR.
assert_eq!(world.query::<&A>().query(&world).count(), 1); | ||
assert_eq!( | ||
world | ||
.query_filtered::<&Observer, Allows<Internal>>() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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_entities
to 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_entities
just a query?Testing
I added a
world.spawn(Internal)
during world bootstrap and most tests succeeded still.