Skip to content

Commit ab286d5

Browse files
committed
Add integration test
Fixes #382
1 parent 907d1ae commit ab286d5

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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::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 test message to the
15+
/// server.
16+
fn main() {
17+
let args: Vec<String> = env::args().collect();
18+
let token = args.get(1).expect("missing argument");
19+
20+
let tx: IpcSender<String> = IpcSender::connect(token.to_string()).expect("connect failed");
21+
tx.send("test message".to_string()).expect("send failed");
22+
23+
process::exit(0);
24+
}

tests/integration_test.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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::IpcOneShotServer;
11+
use std::{env, process};
12+
13+
// These integration tests may be run on their own by issuing:
14+
// cargo test --test '*'
15+
16+
/// Test spawing a process which then acts as a client to a
17+
/// one-shot server in the parent process.
18+
#[test]
19+
fn spawn_one_shot_server_client() {
20+
let executable_path: String = env!("CARGO_BIN_EXE_spawn_client_test_helper").to_string();
21+
22+
let (server, token) =
23+
IpcOneShotServer::<String>::new().expect("Failed to create IPC one-shot server.");
24+
25+
let mut command = process::Command::new(executable_path);
26+
let child_process = command.arg(token);
27+
28+
let mut child = child_process
29+
.spawn()
30+
.expect("Failed to start child process");
31+
32+
let (_rx, msg) = server.accept().expect("accept failed");
33+
assert_eq!("test message", msg);
34+
35+
let result = child.wait().expect("wait for child process failed");
36+
assert!(
37+
result.success(),
38+
"child process failed with exit status code {}",
39+
result.code().expect("exit status code not available")
40+
);
41+
}

0 commit comments

Comments
 (0)