Skip to content

Commit

Permalink
Use get_max_fragment_size for medium_data tests
Browse files Browse the repository at this point in the history
Some platforms like illumos have smaller buffer sizes, so use
`get_max_fragment_size` which shouldn't block under ordinary circumstances.

It would also be nice to move all of the fetches to other threads, but this
appears to work quite well.

See #101.
  • Loading branch information
sunshowers committed Oct 18, 2024
1 parent 4e51f95 commit ef80552
Showing 1 changed file with 31 additions and 9 deletions.
40 changes: 31 additions & 9 deletions src/platform/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ fn multisender_transfer() {

#[test]
fn medium_data() {
let data: Vec<u8> = (0..65536).map(|i| (i % 251) as u8).collect();
let data: Vec<u8> = (0..get_max_fragment_size())
.map(|i| (i % 251) as u8)
.collect();
let data: &[u8] = &data[..];
let (tx, rx) = platform::channel().unwrap();
tx.send(data, vec![], vec![]).unwrap();
Expand All @@ -118,7 +120,9 @@ fn medium_data() {

#[test]
fn medium_data_with_sender_transfer() {
let data: Vec<u8> = (0..65536).map(|i| (i % 251) as u8).collect();
let data: Vec<u8> = (0..get_max_fragment_size())
.map(|i| (i % 251) as u8)
.collect();
let data: &[u8] = &data[..];
let (super_tx, super_rx) = platform::channel().unwrap();
let (sub_tx, sub_rx) = platform::channel().unwrap();
Expand Down Expand Up @@ -181,7 +185,9 @@ fn big_data_with_sender_transfer() {
assert_eq!(ipc_message.os_ipc_channels.len(), 1);
assert_eq!(ipc_message.os_ipc_shared_memory_regions.len(), 0);

let data: Vec<u8> = (0..65536).map(|i| (i % 251) as u8).collect();
let data: Vec<u8> = (0..get_max_fragment_size())
.map(|i| (i % 251) as u8)
.collect();
let data: &[u8] = &data[..];
let sub_tx = ipc_message.os_ipc_channels[0].to_sender();
sub_tx.send(data, vec![], vec![]).unwrap();
Expand All @@ -207,7 +213,9 @@ fn with_n_fds(n: usize, size: usize) {
assert_eq!(ipc_message.os_ipc_channels.len(), receivers.len());
assert_eq!(ipc_message.os_ipc_shared_memory_regions.len(), 0);

let data: Vec<u8> = (0..65536).map(|i| (i % 251) as u8).collect();
let data: Vec<u8> = (0..get_max_fragment_size())
.map(|i| (i % 251) as u8)
.collect();
for (mut sender_fd, sub_rx) in ipc_message
.os_ipc_channels
.into_iter()
Expand All @@ -224,7 +232,12 @@ fn with_n_fds(n: usize, size: usize) {
// These tests only apply to platforms that need fragmentation.
#[cfg(all(
not(feature = "force-inprocess"),
any(target_os = "linux", target_os = "freebsd", target_os = "windows")
any(
target_os = "linux",
target_os = "freebsd",
target_os = "illumos",
target_os = "windows",
)
))]
mod fragment_tests {
use super::with_n_fds;
Expand Down Expand Up @@ -324,7 +337,9 @@ macro_rules! create_big_data_with_n_fds {
assert_eq!(ipc_message.os_ipc_channels.len(), receivers.len());
assert_eq!(ipc_message.os_ipc_shared_memory_regions.len(), 0);

let data: Vec<u8> = (0..65536).map(|i| (i % 251) as u8).collect();
let data: Vec<u8> = (0..get_max_fragment_size())
.map(|i| (i % 251) as u8)
.collect();
let data: &[u8] = &data[..];
for (mut sender_fd, sub_rx) in ipc_message
.os_ipc_channels
Expand Down Expand Up @@ -541,8 +556,10 @@ fn receiver_set_medium_data() {
let rx0_id = rx_set.add(rx0).unwrap();
let rx1_id = rx_set.add(rx1).unwrap();

let data0: Vec<u8> = (0..65536).map(|offset| (offset % 127) as u8).collect();
let data1: Vec<u8> = (0..65536)
let data0: Vec<u8> = (0..get_max_fragment_size())
.map(|offset| (offset % 127) as u8)
.collect();
let data1: Vec<u8> = (0..get_max_fragment_size())
.map(|offset| (offset % 127) as u8 | 0x80)
.collect();

Expand All @@ -552,7 +569,7 @@ fn receiver_set_medium_data() {
while !received0 || !received1 {
for result in rx_set.select().unwrap().into_iter() {
let (received_id, mut ipc_message) = result.unwrap();
ipc_message.data.truncate(65536);
ipc_message.data.truncate(get_max_fragment_size());
assert!(received_id == rx0_id || received_id == rx1_id);
if received_id == rx0_id {
assert_eq!(ipc_message.data, data0);
Expand Down Expand Up @@ -1176,3 +1193,8 @@ fn cross_process_two_step_transfer_spawn() {
assert!(child_exit_code.success());
assert_eq!(ipc_message, IpcMessage::from_data(cookie.to_vec()));
}

fn get_max_fragment_size() -> usize {
// Some platforms have a very large max fragment size, so cap it to a reasonable value.
OsIpcSender::get_max_fragment_size().min(65536)
}

0 comments on commit ef80552

Please sign in to comment.