Skip to content

Commit

Permalink
Add integration test (#383)
Browse files Browse the repository at this point in the history
* Add integration test

Fixes #382

* Skip integration test where not appropriate
  • Loading branch information
glyn authored Jan 25, 2025
1 parent 907d1ae commit e1ad621
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/bin/spawn_client_test_helper.rs
Original file line number Diff line number Diff line change
@@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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<String> = env::args().collect();
let token = args.get(1).expect("missing argument");

let tx: IpcSender<String> = IpcSender::connect(token.to_string()).expect("connect failed");
tx.send("test message".to_string()).expect("send failed");

process::exit(0);
}
44 changes: 44 additions & 0 deletions tests/integration_test.rs
Original file line number Diff line number Diff line change
@@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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::<String>::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")
);
}

0 comments on commit e1ad621

Please sign in to comment.