|
| 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