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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//! A process that keeps running and keeps printing — the fixture the process
//! handle tests need.
//!
//! `shell_start` exists for work that does not finish on its own, so proving it
//! works needs a program that does not finish on its own. There is no such
//! program that behaves the same on macOS, Linux and Windows: `tail -f` and
//! `sleep` are not on a Windows runner, `timeout` means two different things,
//! and a shell loop is exactly what this crate refuses to hand to a shell. So
//! the fixture is written here, in Rust, and is the same program everywhere.
//!
//! It prints `tick N` once every `TICK_MS` milliseconds and flushes each line,
//! because a line sitting in a buffer is indistinguishable from a process that
//! has not written it, and the whole point of a poll is to see output while the
//! process is still alive.
//!
//! Arguments: `tick [count]`. With no count it runs until it is killed, which is
//! the case the kill tests want. With one it exits after that many lines, which
//! is the case the self-exit test wants.
//!
//! Run directly rather than as a test: `cargo run --example tick 3`.
use Write;
/// Slow enough that a test can poll between two lines without racing, fast
/// enough that a test waiting for three of them is not slow.
const TICK_MS: u64 = 120;
/// How long this runs before giving up on being killed.
///
/// A fixture whose whole job is to outlive its caller will outlive a caller that
/// dies badly — a `SIGKILL`ed test binary runs no `Drop`, so nothing kills what
/// it started. Left alone these accumulate across runs and quietly degrade every
/// later one. The ceiling is far longer than any test that uses this and short
/// enough that a leak is measured in minutes rather than until reboot.
const CEILING: Duration = from_secs;