Skip to content

Commit 1da726e

Browse files
authored
Fix a change detection test (#8605)
# Objective The unit test `chang_tick_wraparound` is meant to ensure that change ticks correctly deal with wrapping by setting the world's `last_change_tick` to `u32::MAX`. However, since systems don't use* the value of `World::last_change_tick`, this test doesn't actually involve any wrapping behavior. *exclusive systems do use `World::last_change_tick`; however it gets overwritten by the system's own last tick in `System::run`. ## Solution Use `QueryState` instead of systems in the unit test. This approach actually uses `World::last_change_tick`, so it properly tests that change ticks deal with wrapping correctly.
1 parent 08bf1a6 commit 1da726e

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

crates/bevy_ecs/src/change_detection.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -814,24 +814,19 @@ mod tests {
814814

815815
#[test]
816816
fn change_tick_wraparound() {
817-
fn change_detected(query: Query<Ref<C>>) -> bool {
818-
query.single().is_changed()
819-
}
820-
821817
let mut world = World::new();
822818
world.last_change_tick = Tick::new(u32::MAX);
823819
*world.change_tick.get_mut() = 0;
824820

825821
// component added: 0, changed: 0
826822
world.spawn(C);
827823

828-
// system last ran: u32::MAX
829-
let mut change_detected_system = IntoSystem::into_system(change_detected);
830-
change_detected_system.initialize(&mut world);
824+
world.increment_change_tick();
831825

832826
// Since the world is always ahead, as long as changes can't get older than `u32::MAX` (which we ensure),
833827
// the wrapping difference will always be positive, so wraparound doesn't matter.
834-
assert!(change_detected_system.run((), &mut world));
828+
let mut query = world.query::<Ref<C>>();
829+
assert!(query.single(&world).is_changed());
835830
}
836831

837832
#[test]

0 commit comments

Comments
 (0)