1111//! the bootstrap binary, which is not built in test mode (and anyway, test mode
1212//! does not work across crate boundaries)
1313
14+ #[ cfg( test) ]
1415use std:: collections:: HashSet ;
1516use std:: collections:: VecDeque ;
17+ #[ cfg( test) ]
1618use std:: time:: Duration ;
1719
1820use async_trait:: async_trait;
@@ -27,17 +29,23 @@ use hyperactor::Named;
2729use hyperactor:: PortRef ;
2830use hyperactor:: RefClient ;
2931use hyperactor:: Unbind ;
32+ #[ cfg( test) ]
3033use hyperactor:: clock:: Clock as _;
34+ #[ cfg( test) ]
3135use hyperactor:: clock:: RealClock ;
36+ #[ cfg( test) ]
3237use hyperactor:: mailbox;
3338use hyperactor:: supervision:: ActorSupervisionEvent ;
3439use ndslice:: Point ;
35- use ndslice:: ViewExt ;
40+ #[ cfg( test) ]
41+ use ndslice:: ViewExt as _;
3642use serde:: Deserialize ;
3743use serde:: Serialize ;
3844
3945use crate :: comm:: multicast:: CastInfo ;
46+ #[ cfg( test) ]
4047use crate :: v1:: ActorMesh ;
48+ #[ cfg( test) ]
4149use crate :: v1:: ActorMeshRef ;
4250#[ cfg( test) ]
4351use crate :: v1:: testing;
@@ -212,28 +220,7 @@ impl Handler<GetCastInfo> for TestActor {
212220pub async fn assert_mesh_shape ( actor_mesh : ActorMesh < TestActor > ) {
213221 let instance = testing:: instance ( ) . await ;
214222 // Verify casting to the root actor mesh
215- {
216- let ( port, mut rx) = mailbox:: open_port ( & instance) ;
217- actor_mesh. cast ( instance, GetActorId ( port. bind ( ) ) ) . unwrap ( ) ;
218-
219- let mut expected_actor_ids: HashSet < _ > = actor_mesh
220- . values ( )
221- . map ( |actor_ref| actor_ref. actor_id ( ) . clone ( ) )
222- . collect ( ) ;
223-
224- while !expected_actor_ids. is_empty ( ) {
225- let actor_id = rx. recv ( ) . await . unwrap ( ) ;
226- assert ! (
227- expected_actor_ids. remove( & actor_id) ,
228- "got {actor_id}, expect {expected_actor_ids:?}"
229- ) ;
230- }
231-
232- // No more messages
233- RealClock . sleep ( Duration :: from_secs ( 1 ) ) . await ;
234- let result = rx. try_recv ( ) ;
235- assert ! ( result. as_ref( ) . unwrap( ) . is_none( ) , "got {result:?}" ) ;
236- }
223+ verify_casting ( & actor_mesh, instance) . await ;
237224
238225 // Just pick the first dimension. Slice half of it off.
239226 // actor_mesh.extent().
@@ -242,28 +229,30 @@ pub async fn assert_mesh_shape(actor_mesh: ActorMesh<TestActor>) {
242229
243230 // Verify casting to the sliced actor mesh
244231 let sliced_actor_mesh = actor_mesh. range ( & label, 0 ..size) . unwrap ( ) ;
245- {
246- let ( port, mut rx) = mailbox:: open_port ( instance) ;
247- sliced_actor_mesh
248- . cast ( instance, GetActorId ( port. bind ( ) ) )
249- . unwrap ( ) ;
232+ verify_casting ( & sliced_actor_mesh, instance) . await ;
233+ }
250234
251- let mut expected_actor_ids: HashSet < _ > = sliced_actor_mesh
252- . values ( )
253- . map ( |actor_ref| actor_ref. actor_id ( ) . clone ( ) )
254- . collect ( ) ;
235+ #[ cfg( test) ]
236+ /// Cast to the actor mesh, and verify that all actors are reached.
237+ pub async fn verify_casting ( actor_mesh : & ActorMeshRef < TestActor > , instance : & Instance < ( ) > ) {
238+ let ( port, mut rx) = mailbox:: open_port ( instance) ;
239+ actor_mesh. cast ( instance, GetActorId ( port. bind ( ) ) ) . unwrap ( ) ;
255240
256- while !expected_actor_ids. is_empty ( ) {
257- let actor_id = rx. recv ( ) . await . unwrap ( ) ;
258- assert ! (
259- expected_actor_ids. remove( & actor_id) ,
260- "got {actor_id}, expect {expected_actor_ids:?}"
261- ) ;
262- }
241+ let mut expected_actor_ids: HashSet < _ > = actor_mesh
242+ . values ( )
243+ . map ( |actor_ref| actor_ref. actor_id ( ) . clone ( ) )
244+ . collect ( ) ;
263245
264- // No more messages
265- RealClock . sleep ( Duration :: from_secs ( 1 ) ) . await ;
266- let result = rx. try_recv ( ) ;
267- assert ! ( result. as_ref( ) . unwrap( ) . is_none( ) , "got {result:?}" ) ;
246+ while !expected_actor_ids. is_empty ( ) {
247+ let actor_id = rx. recv ( ) . await . unwrap ( ) ;
248+ assert ! (
249+ expected_actor_ids. remove( & actor_id) ,
250+ "got {actor_id}, expect {expected_actor_ids:?}"
251+ ) ;
268252 }
253+
254+ // No more messages
255+ RealClock . sleep ( Duration :: from_secs ( 1 ) ) . await ;
256+ let result = rx. try_recv ( ) ;
257+ assert ! ( result. as_ref( ) . unwrap( ) . is_none( ) , "got {result:?}" ) ;
269258}
0 commit comments