@@ -38,14 +38,16 @@ use hyperactor::mailbox;
3838use hyperactor:: supervision:: ActorSupervisionEvent ;
3939use ndslice:: Point ;
4040#[ cfg( test) ]
41- use ndslice:: ViewExt ;
41+ use ndslice:: ViewExt as _ ;
4242use serde:: Deserialize ;
4343use serde:: Serialize ;
4444
4545use crate :: comm:: multicast:: CastInfo ;
4646#[ cfg( test) ]
4747use crate :: v1:: ActorMesh ;
4848#[ cfg( test) ]
49+ use crate :: v1:: ActorMeshRef ;
50+ #[ cfg( test) ]
4951use crate :: v1:: testing;
5052
5153/// A simple test actor used by various unit tests.
@@ -218,28 +220,7 @@ impl Handler<GetCastInfo> for TestActor {
218220pub async fn assert_mesh_shape ( actor_mesh : ActorMesh < TestActor > ) {
219221 let instance = testing:: instance ( ) . await ;
220222 // Verify casting to the root actor mesh
221- {
222- let ( port, mut rx) = mailbox:: open_port ( & instance) ;
223- actor_mesh. cast ( instance, GetActorId ( port. bind ( ) ) ) . unwrap ( ) ;
224-
225- let mut expected_actor_ids: HashSet < _ > = actor_mesh
226- . values ( )
227- . map ( |actor_ref| actor_ref. actor_id ( ) . clone ( ) )
228- . collect ( ) ;
229-
230- while !expected_actor_ids. is_empty ( ) {
231- let actor_id = rx. recv ( ) . await . unwrap ( ) ;
232- assert ! (
233- expected_actor_ids. remove( & actor_id) ,
234- "got {actor_id}, expect {expected_actor_ids:?}"
235- ) ;
236- }
237-
238- // No more messages
239- RealClock . sleep ( Duration :: from_secs ( 1 ) ) . await ;
240- let result = rx. try_recv ( ) ;
241- assert ! ( result. as_ref( ) . unwrap( ) . is_none( ) , "got {result:?}" ) ;
242- }
223+ assert_casting_correctness ( & actor_mesh, instance) . await ;
243224
244225 // Just pick the first dimension. Slice half of it off.
245226 // actor_mesh.extent().
@@ -248,28 +229,33 @@ pub async fn assert_mesh_shape(actor_mesh: ActorMesh<TestActor>) {
248229
249230 // Verify casting to the sliced actor mesh
250231 let sliced_actor_mesh = actor_mesh. range ( & label, 0 ..size) . unwrap ( ) ;
251- {
252- let ( port, mut rx) = mailbox:: open_port ( instance) ;
253- sliced_actor_mesh
254- . cast ( instance, GetActorId ( port. bind ( ) ) )
255- . unwrap ( ) ;
232+ assert_casting_correctness ( & sliced_actor_mesh, instance) . await ;
233+ }
256234
257- let mut expected_actor_ids: HashSet < _ > = sliced_actor_mesh
258- . values ( )
259- . map ( |actor_ref| actor_ref. actor_id ( ) . clone ( ) )
260- . collect ( ) ;
235+ #[ cfg( test) ]
236+ /// Cast to the actor mesh, and verify that all actors are reached.
237+ pub async fn assert_casting_correctness (
238+ actor_mesh : & ActorMeshRef < TestActor > ,
239+ instance : & Instance < ( ) > ,
240+ ) {
241+ let ( port, mut rx) = mailbox:: open_port ( instance) ;
242+ actor_mesh. cast ( instance, GetActorId ( port. bind ( ) ) ) . unwrap ( ) ;
261243
262- while !expected_actor_ids. is_empty ( ) {
263- let actor_id = rx. recv ( ) . await . unwrap ( ) ;
264- assert ! (
265- expected_actor_ids. remove( & actor_id) ,
266- "got {actor_id}, expect {expected_actor_ids:?}"
267- ) ;
268- }
244+ let mut expected_actor_ids: HashSet < _ > = actor_mesh
245+ . values ( )
246+ . map ( |actor_ref| actor_ref. actor_id ( ) . clone ( ) )
247+ . collect ( ) ;
269248
270- // No more messages
271- RealClock . sleep ( Duration :: from_secs ( 1 ) ) . await ;
272- let result = rx. try_recv ( ) ;
273- assert ! ( result. as_ref( ) . unwrap( ) . is_none( ) , "got {result:?}" ) ;
249+ while !expected_actor_ids. is_empty ( ) {
250+ let actor_id = rx. recv ( ) . await . unwrap ( ) ;
251+ assert ! (
252+ expected_actor_ids. remove( & actor_id) ,
253+ "got {actor_id}, expect {expected_actor_ids:?}"
254+ ) ;
274255 }
256+
257+ // No more messages
258+ RealClock . sleep ( Duration :: from_secs ( 1 ) ) . await ;
259+ let result = rx. try_recv ( ) ;
260+ assert ! ( result. as_ref( ) . unwrap( ) . is_none( ) , "got {result:?}" ) ;
275261}
0 commit comments