| @@ -822,3 +822,61 @@ fn read_response(conn: &mut impl std::io::BufRead) -> (String, Vec<u8>) { |
| 822 | 822 | conn.read_exact(&mut body).unwrap(); |
| 823 | 823 | (head, body) |
| 824 | 824 | } |
| 825 | + |
| 826 | +/// Issue #72: a program whose stdout nobody reads keeps running. With one |
| 827 | +/// scheduler thread, the actor flooding stdout parks once the pipe and |
| 828 | +/// the console's queue are full, and the other actor still runs; once |
| 829 | +/// stdout is read, the flood ends and the program exits normally. |
| 830 | +#[test] |
| 831 | +fn a_full_stdout_parks_the_writer_not_the_thread() { |
| 832 | + use std::io::{BufRead, BufReader, Read}; |
| 833 | + use std::time::Duration; |
| 834 | + let lib = std::path::Path::new(env!("CARGO_BIN_EXE_louise")).with_file_name("liblouise_rt.a"); |
| 835 | + if !lib.is_file() { |
| 836 | + eprintln!("skipping: {} not built", lib.display()); |
| 837 | + return; |
| 838 | + } |
| 839 | + let exe = std::path::PathBuf::from(env!("CARGO_TARGET_TMPDIR")).join("console-stalled"); |
| 840 | + let (ok, _, stderr) = louise(&[ |
| 841 | + "build", |
| 842 | + "tests/fixtures/console/stalled.lse", |
| 843 | + "-o", |
| 844 | + exe.to_str().unwrap(), |
| 845 | + ]); |
| 846 | + assert!(ok, "{stderr}"); |
| 847 | + let mut program = Command::new(&exe) |
| 848 | + .env("LOUISE_THREADS", "1") |
| 849 | + .stdout(std::process::Stdio::piped()) |
| 850 | + .stderr(std::process::Stdio::piped()) |
| 851 | + .spawn() |
| 852 | + .unwrap(); |
| 853 | + let mut errors = BufReader::new(program.stderr.take().unwrap()); |
| 854 | + let mut port = String::new(); |
| 855 | + errors.read_line(&mut port).unwrap(); |
| 856 | + let port: u16 = port.trim().parse().expect("the program prints its port"); |
| 857 | + let conn = std::net::TcpStream::connect(("127.0.0.1", port)).unwrap(); |
| 858 | + conn.set_read_timeout(Some(Duration::from_secs(10))) |
| 859 | + .unwrap(); |
| 860 | + let mut alive = String::new(); |
| 861 | + let read = BufReader::new(conn).read_line(&mut alive); |
| 862 | + if read.is_err() || alive != "alive\n" { |
| 863 | + let _ = program.kill(); |
| 864 | + panic!("the program stalled while its stdout was full ({read:?}, {alive:?})"); |
| 865 | + } |
| 866 | + let mut out = String::new(); |
| 867 | + program |
| 868 | + .stdout |
| 869 | + .take() |
| 870 | + .unwrap() |
| 871 | + .read_to_string(&mut out) |
| 872 | + .unwrap(); |
| 873 | + let status = program.wait().unwrap(); |
| 874 | + let mut rest = String::new(); |
| 875 | + errors.read_to_string(&mut rest).unwrap(); |
| 876 | + assert!(status.success(), "{rest}"); |
| 877 | + let lines: Vec<&str> = out.lines().collect(); |
| 878 | + assert_eq!(lines.len(), 20001); |
| 879 | + assert!(lines[0].starts_with("line 20000: "), "{}", lines[0]); |
| 880 | + assert!(lines[19999].starts_with("line 1: "), "{}", lines[19999]); |
| 881 | + assert_eq!(lines[20000], "done"); |
| 882 | +} |