@@ -61,8 +61,9 @@ impl<T> DebugCheckedUnwrap for Option<T> {
61
61
#[ cfg( test) ]
62
62
mod tests {
63
63
use super :: { ReadOnlyWorldQuery , WorldQuery } ;
64
- use crate :: prelude:: { AnyOf , Entity , Or , QueryState , With , Without } ;
64
+ use crate :: prelude:: { AnyOf , Changed , Entity , Or , QueryState , With , Without } ;
65
65
use crate :: query:: { ArchetypeFilter , QueryCombinationIter } ;
66
+ use crate :: schedule:: { IntoSystemConfigs , Schedule } ;
66
67
use crate :: system:: { IntoSystem , Query , System , SystemState } ;
67
68
use crate :: { self as bevy_ecs, component:: Component , world:: World } ;
68
69
use std:: any:: type_name;
@@ -749,4 +750,32 @@ mod tests {
749
750
let _: [ & Foo ; 1 ] = q. many ( [ e] ) ;
750
751
let _: & Foo = q. single ( ) ;
751
752
}
753
+
754
+ #[ test]
755
+ fn par_iter_mut_change_detection ( ) {
756
+ let mut world = World :: new ( ) ;
757
+ world. spawn ( ( A ( 1 ) , B ( 1 ) ) ) ;
758
+
759
+ fn propagate_system ( mut query : Query < ( & A , & mut B ) , Changed < A > > ) {
760
+ query. par_iter_mut ( ) . for_each_mut ( |( a, mut b) | {
761
+ b. 0 = a. 0 ;
762
+ } ) ;
763
+ }
764
+
765
+ fn modify_system ( mut query : Query < & mut A > ) {
766
+ for mut a in & mut query {
767
+ a. 0 = 2 ;
768
+ }
769
+ }
770
+
771
+ let mut schedule = Schedule :: new ( ) ;
772
+ schedule. add_systems ( ( propagate_system, modify_system) . chain ( ) ) ;
773
+ schedule. run ( & mut world) ;
774
+ world. clear_trackers ( ) ;
775
+ schedule. run ( & mut world) ;
776
+ world. clear_trackers ( ) ;
777
+
778
+ let values = world. query :: < & B > ( ) . iter ( & world) . collect :: < Vec < & B > > ( ) ;
779
+ assert_eq ! ( values, vec![ & B ( 2 ) ] ) ;
780
+ }
752
781
}
0 commit comments