Skip to content

Commit 584a950

Browse files
committed
Integration test of used IpcReceiver transmission
1 parent 9a75c35 commit 584a950

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2025 The Servo Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution.
3+
//
4+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7+
// option. This file may not be copied, modified, or distributed
8+
// except according to those terms.
9+
10+
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
11+
use std::{env, process};
12+
13+
/// Test executable which connects to the one-shot server with name
14+
/// passed in as an argument and then sends a receiver which it has
15+
/// already used to the server and then sends a test message to the
16+
/// receiver.
17+
fn main() {
18+
let args: Vec<String> = env::args().collect();
19+
let token = args.get(1).expect("missing argument");
20+
21+
let (sub_tx, sub_rx) = ipc::channel().unwrap();
22+
sub_tx.send("test message".to_string()).expect("send failed");
23+
let msg = sub_rx.recv().unwrap();
24+
assert_eq!("test message", msg);
25+
26+
let tx: IpcSender<IpcReceiver<String>> = IpcSender::connect(token.to_string()).expect("connect failed");
27+
tx.send(sub_rx).expect("send failed");
28+
sub_tx.send("test message".to_string()).expect("send failed");
29+
30+
process::exit(0);
31+
}

tests/integration_test.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,35 @@ fn spawn_receiver_sender_client() {
7373
result.code().expect("exit status code not available")
7474
);
7575
}
76+
77+
/// Test spawing a process which then acts as a client to a
78+
/// one-shot server in the parent process. The client sends a
79+
/// receiver, which it has already used, and then send a
80+
/// message to the receiver.
81+
#[cfg(not(any(feature = "force-inprocess", target_os = "android", target_os = "ios")))]
82+
#[test]
83+
fn spawn_used_receiver_sender_client() {
84+
let executable_path: String = env!("CARGO_BIN_EXE_spawn_used_receiver_sender_client").to_string();
85+
86+
let (server, token) =
87+
IpcOneShotServer::<IpcReceiver<String>>::new().expect("Failed to create IPC one-shot server.");
88+
89+
let mut command = process::Command::new(executable_path);
90+
let child_process = command.arg(token);
91+
92+
let mut child = child_process
93+
.spawn()
94+
.expect("Failed to start child process");
95+
96+
let (_rx, sub_rx) = server.accept().expect("accept failed");
97+
98+
let msg = sub_rx.recv().unwrap();
99+
assert_eq!("test message", msg);
100+
101+
let result = child.wait().expect("wait for child process failed");
102+
assert!(
103+
result.success(),
104+
"child process failed with exit status code {}",
105+
result.code().expect("exit status code not available")
106+
);
107+
}

0 commit comments

Comments
 (0)