Skip to content

Commit 92618a7

Browse files
dstaay-fbfacebook-github-bot
authored andcommitted
Persist buffers in test infra (#454)
Summary: Pull Request resolved: #454 Due to lifecycle management in rust, we need to keep around reference of native Box<T> in order to keep raw memory ptr accurate. In practice, without this change, a lot of tests will pass, even when send wasn't transmitted; so this just makes existing tests more accurate. Reviewed By: allenwang28 Differential Revision: D77897840 fbshipit-source-id: bff2e4bcf623b015e844abf066a428237e03b02a
1 parent eb4d4de commit 92618a7

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

monarch_rdma/src/test_utils.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ pub mod test_utils {
4444
) -> Result<bool, anyhow::Error> {
4545
let timeout = Duration::from_secs(timeout_secs);
4646
let start_time = Instant::now();
47-
4847
while start_time.elapsed() < timeout {
4948
match qp.poll_completion() {
5049
Ok(Some(wc)) => {
@@ -61,7 +60,7 @@ pub mod test_utils {
6160
}
6261
}
6362

64-
Ok(false)
63+
Err(anyhow::Error::msg("Timeout while waiting for completion"))
6564
}
6665

6766
pub struct RdmaManagerTestEnv<'a> {
@@ -81,6 +80,7 @@ pub mod test_utils {
8180
pub struct Buffer {
8281
ptr: u64,
8382
len: usize,
83+
cpu_ref: Option<Box<[u8]>>,
8484
}
8585
impl RdmaManagerTestEnv<'_> {
8686
/// Sets up the RDMA test environment.
@@ -180,6 +180,7 @@ pub mod test_utils {
180180
buf_vec.push(Buffer {
181181
ptr: buffer.as_mut_ptr() as u64,
182182
len: buffer.len(),
183+
cpu_ref: Some(buffer),
183184
});
184185
continue;
185186
}
@@ -267,12 +268,11 @@ pub mod test_utils {
267268
buf_vec.push(Buffer {
268269
ptr: dptr,
269270
len: padded_size,
271+
cpu_ref: None,
270272
});
271273
}
272274
}
273275

274-
let _buffer1 = vec![0u8; buffer_size].into_boxed_slice();
275-
let _buffer2 = vec![0u8; buffer_size].into_boxed_slice();
276276
// Fill buffer1 with test data
277277
if device_str1.0 == "cuda" {
278278
let mut temp_buffer = vec![0u8; buffer_size].into_boxed_slice();
@@ -294,7 +294,6 @@ pub mod test_utils {
294294
}
295295
}
296296
}
297-
298297
let actor_1 = actor_mesh_1.get(0).unwrap();
299298
let actor_2 = actor_mesh_2.get(0).unwrap();
300299

@@ -306,9 +305,11 @@ pub mod test_utils {
306305
.await?;
307306
// Get keys from both actors.
308307

308+
let buffer_2 = buf_vec.remove(1);
309+
let buffer_1 = buf_vec.remove(0);
309310
Ok(Self {
310-
buffer_1: buf_vec[0].clone(),
311-
buffer_2: buf_vec[1].clone(),
311+
buffer_1,
312+
buffer_2,
312313
client_1: proc_mesh_1.client(),
313314
client_2: proc_mesh_2.client(),
314315
actor_1,
@@ -373,11 +374,13 @@ pub mod test_utils {
373374
buf_vec.push(Buffer {
374375
ptr: temp_buffer.as_mut_ptr() as u64,
375376
len: size,
377+
cpu_ref: Some(temp_buffer),
376378
});
377379
} else {
378380
buf_vec.push(Buffer {
379381
ptr: handle.addr as u64,
380382
len: size,
383+
cpu_ref: None,
381384
});
382385
}
383386
}

0 commit comments

Comments
 (0)