diff --git a/src/bin/spawn_client_test_helper.rs b/src/bin/spawn_client_test_helper.rs new file mode 100644 index 00000000..8464ba45 --- /dev/null +++ b/src/bin/spawn_client_test_helper.rs @@ -0,0 +1,24 @@ +// Copyright 2025 The Servo Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use ipc_channel::ipc::IpcSender; +use std::{env, process}; + +/// Test executable which connects to the one-shot server with name +/// passed in as an argument and then sends a test message to the +/// server. +fn main() { + let args: Vec = env::args().collect(); + let token = args.get(1).expect("missing argument"); + + let tx: IpcSender = IpcSender::connect(token.to_string()).expect("connect failed"); + tx.send("test message".to_string()).expect("send failed"); + + process::exit(0); +} diff --git a/tests/integration_test.rs b/tests/integration_test.rs new file mode 100644 index 00000000..92d69e1c --- /dev/null +++ b/tests/integration_test.rs @@ -0,0 +1,44 @@ +// Copyright 2025 The Servo Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#[cfg(not(any(feature = "force-inprocess", target_os = "android", target_os = "ios")))] +use ipc_channel::ipc::IpcOneShotServer; +#[cfg(not(any(feature = "force-inprocess", target_os = "android", target_os = "ios")))] +use std::{env, process}; + +// These integration tests may be run on their own by issuing: +// cargo test --test '*' + +/// Test spawing a process which then acts as a client to a +/// one-shot server in the parent process. +#[cfg(not(any(feature = "force-inprocess", target_os = "android", target_os = "ios")))] +#[test] +fn spawn_one_shot_server_client() { + let executable_path: String = env!("CARGO_BIN_EXE_spawn_client_test_helper").to_string(); + + let (server, token) = + IpcOneShotServer::::new().expect("Failed to create IPC one-shot server."); + + let mut command = process::Command::new(executable_path); + let child_process = command.arg(token); + + let mut child = child_process + .spawn() + .expect("Failed to start child process"); + + let (_rx, msg) = server.accept().expect("accept failed"); + assert_eq!("test message", msg); + + let result = child.wait().expect("wait for child process failed"); + assert!( + result.success(), + "child process failed with exit status code {}", + result.code().expect("exit status code not available") + ); +}