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 3522537
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 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..OsIpcSender::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..OsIpcSender::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..OsIpcSender::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..OsIpcSender::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 Down Expand Up @@ -324,7 +332,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..OsIpcSender::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 +551,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..OsIpcSender::get_max_fragment_size())
.map(|offset| (offset % 127) as u8)
.collect();
let data1: Vec<u8> = (0..OsIpcSender::get_max_fragment_size())
.map(|offset| (offset % 127) as u8 | 0x80)
.collect();

Expand All @@ -552,7 +564,9 @@ 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(OsIpcSender::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

0 comments on commit 3522537

Please sign in to comment.