Skip to content

Commit 0480579

Browse files
committed
tests: Cleanup: avoid need for separate _server() pseudo-tests
Integrate the server functionality right into the main `_spawn()` test functions: running either the server or the client portions as necessary. This further aligns the structure of these tests with the corresponding `_fork()` variants. It also avoids the need for the `#[ignore]`/`--ignored` hack, since all the test functions now always run -- either as normal tests (client parts); or as pseudo-tests, when self-spawned in server mode.
1 parent 3066814 commit 0480579

File tree

2 files changed

+13
-56
lines changed

2 files changed

+13
-56
lines changed

src/platform/test.rs

Lines changed: 11 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -648,31 +648,21 @@ fn server_connect_first() {
648648
(data, vec![], vec![]));
649649
}
650650

651-
// Note! This test is actually used by the cross_process_spawn() test
652-
// below as a second process. Running it by itself is meaningless, but
653-
// passes.
654651
#[cfg(not(any(feature = "force-inprocess", target_os = "windows", target_os = "android")))]
655652
#[test]
656-
#[ignore]
657-
fn cross_process_server()
658-
{
653+
fn cross_process_spawn() {
659654
let data: &[u8] = b"1234567";
655+
660656
let channel_name = get_channel_name_arg("server");
661657
if let Some(channel_name) = channel_name {
662658
let tx = OsIpcSender::connect(channel_name).unwrap();
663659
tx.send(data, vec![], vec![]).unwrap();
664660

665661
unsafe { libc::exit(0); }
666662
}
667-
}
668663

669-
#[cfg(not(any(feature = "force-inprocess", target_os = "windows", target_os = "android")))]
670-
#[test]
671-
fn cross_process_spawn() {
672664
let (server, name) = OsIpcOneShotServer::new().unwrap();
673-
let data: &[u8] = b"1234567";
674-
675-
let mut child_pid = spawn_server("cross_process_server", &[("server", &*name)]);
665+
let mut child_pid = spawn_server("cross_process_spawn", &[("server", &*name)]);
676666

677667
let (_, received_data, received_channels, received_shared_memory_regions) =
678668
server.accept().unwrap();
@@ -699,14 +689,9 @@ fn cross_process_fork() {
699689
(data, vec![], vec![]));
700690
}
701691

702-
// Note! This test is actually used by the cross_process_sender_transfer_spawn() test
703-
// below as a second process. Running it by itself is meaningless, but
704-
// passes.
705692
#[cfg(not(any(feature = "force-inprocess", target_os = "windows", target_os = "android")))]
706693
#[test]
707-
#[ignore]
708-
fn cross_process_sender_transfer_server()
709-
{
694+
fn cross_process_sender_transfer_spawn() {
710695
let channel_name = get_channel_name_arg("server");
711696
if let Some(channel_name) = channel_name {
712697
let super_tx = OsIpcSender::connect(channel_name).unwrap();
@@ -719,15 +704,9 @@ fn cross_process_sender_transfer_server()
719704

720705
unsafe { libc::exit(0); }
721706
}
722-
}
723707

724-
#[cfg(not(any(feature = "force-inprocess", target_os = "windows", target_os = "android")))]
725-
#[test]
726-
fn cross_process_sender_transfer_spawn() {
727708
let (server, name) = OsIpcOneShotServer::new().unwrap();
728-
729-
let mut child_pid = spawn_server("cross_process_sender_transfer_server",
730-
&[("server", &*name)]);
709+
let mut child_pid = spawn_server("cross_process_sender_transfer_spawn", &[("server", &*name)]);
731710

732711
let (super_rx, _, mut received_channels, _) = server.accept().unwrap();
733712
assert_eq!(received_channels.len(), 1);
@@ -937,15 +916,14 @@ mod sync_test {
937916
}
938917
}
939918

940-
// Note! This test is actually used by the
941-
// cross_process_two_step_transfer_spawn() test below. Running it by
942-
// itself is meaningless, but it passes if run this way.
919+
// TODO -- this fails on OSX with a MACH_SEND_INVALID_RIGHT!
920+
// Needs investigation.
943921
#[cfg(not(any(feature = "force-inprocess", target_os = "windows", target_os = "android")))]
922+
#[cfg_attr(target_os = "macos", ignore)]
944923
#[test]
945-
#[ignore]
946-
fn cross_process_two_step_transfer_server()
947-
{
924+
fn cross_process_two_step_transfer_spawn() {
948925
let cookie: &[u8] = b"cookie";
926+
949927
let channel_name = get_channel_name_arg("server");
950928
if let Some(channel_name) = channel_name {
951929
// connect by name to our other process
@@ -977,15 +955,6 @@ fn cross_process_two_step_transfer_server()
977955
// terminate
978956
unsafe { libc::exit(0); }
979957
}
980-
}
981-
982-
// TODO -- this fails on OSX with a MACH_SEND_INVALID_RIGHT!
983-
// Needs investigation.
984-
#[cfg(not(any(feature = "force-inprocess", target_os = "windows", target_os = "android")))]
985-
#[cfg_attr(target_os = "macos", ignore)]
986-
#[test]
987-
fn cross_process_two_step_transfer_spawn() {
988-
let cookie: &[u8] = b"cookie";
989958

990959
// create channel 1
991960
let (one_tx, one_rx) = platform::channel().unwrap();
@@ -999,7 +968,7 @@ fn cross_process_two_step_transfer_spawn() {
999968

1000969
// create a one-shot server, and spawn another process
1001970
let (server, name) = OsIpcOneShotServer::new().unwrap();
1002-
let mut child_pid = spawn_server("cross_process_two_step_transfer_server",
971+
let mut child_pid = spawn_server("cross_process_two_step_transfer_spawn",
1003972
&[("server", &*name)]);
1004973

1005974
// The other process will have sent us a transmit channel in received channels

src/test.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ pub fn get_channel_name_arg(which: &str) -> Option<String> {
7777
#[cfg(not(any(feature = "force-inprocess", target_os = "windows", target_os = "android")))]
7878
pub fn spawn_server(test_name: &str, server_args: &[(&str, &str)]) -> process::Child {
7979
Command::new(env::current_exe().unwrap())
80-
.arg("--ignored")
8180
.arg(test_name)
8281
.args(server_args.iter()
8382
.map(|&(ref name, ref val)| format!("channel_name-{}:{}", name, val)))
@@ -170,13 +169,9 @@ fn select() {
170169
}
171170
}
172171

173-
// Note! This test is actually used by the cross_process_embedded_senders_spawn() test
174-
// below as a second process. Running it by itself is meaningless, but
175-
// passes.
176172
#[cfg(not(any(feature = "force-inprocess", target_os = "windows", target_os = "android")))]
177173
#[test]
178-
#[ignore]
179-
fn cross_process_embedded_senders_server() {
174+
fn cross_process_embedded_senders_spawn() {
180175
let person = ("Patrick Walton".to_owned(), 29);
181176

182177
let server0_name = get_channel_name_arg("server0");
@@ -191,17 +186,10 @@ fn cross_process_embedded_senders_server() {
191186

192187
unsafe { libc::exit(0); }
193188
}
194-
}
195-
196-
#[cfg(not(any(feature = "force-inprocess", target_os = "windows", target_os = "android")))]
197-
#[test]
198-
fn cross_process_embedded_senders_spawn() {
199-
let person = ("Patrick Walton".to_owned(), 29);
200189

201190
let (server0, server0_name) = IpcOneShotServer::new().unwrap();
202191
let (server2, server2_name) = IpcOneShotServer::new().unwrap();
203-
204-
let mut child_pid = spawn_server("cross_process_embedded_senders_server",
192+
let mut child_pid = spawn_server("cross_process_embedded_senders_spawn",
205193
&[("server0", &*server0_name), ("server2", &*server2_name)]);
206194

207195
let (_, tx1): (_, IpcSender<Person>) = server0.accept().unwrap();

0 commit comments

Comments
 (0)