File: process_change_of_runtime.rs

package info (click to toggle)
rustc 1.85.0%2Bdfsg3-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, sid, trixie
  • size: 893,396 kB
  • sloc: xml: 158,127; python: 35,830; javascript: 19,497; cpp: 19,002; sh: 17,245; ansic: 13,127; asm: 4,376; makefile: 1,051; perl: 29; lisp: 29; ruby: 19; sql: 11
file content (34 lines) | stat: -rw-r--r-- 1,055 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#![cfg(feature = "process")]
#![warn(rust_2018_idioms)]
// This tests test the behavior of `process::Command::spawn` when it is used
// outside runtime, and when `process::Child::wait ` is used in a different
// runtime from which `process::Command::spawn` is used.
#![cfg(all(unix, not(target_os = "freebsd"), not(miri)))]

use std::process::Stdio;
use tokio::{process::Command, runtime::Runtime};

#[test]
fn process_spawned_and_wait_in_different_runtime() {
    let mut child = Runtime::new().unwrap().block_on(async {
        Command::new("true")
            .stdin(Stdio::piped())
            .stdout(Stdio::null())
            .spawn()
            .unwrap()
    });
    Runtime::new().unwrap().block_on(async {
        let _ = child.wait().await.unwrap();
    });
}

#[test]
#[should_panic(
    expected = "there is no reactor running, must be called from the context of a Tokio 1.x runtime"
)]
fn process_spawned_outside_runtime() {
    let _ = Command::new("true")
        .stdin(Stdio::piped())
        .stdout(Stdio::null())
        .spawn();
}