Skip to content

Commit

Permalink
Fix flaky test, hopefully
Browse files Browse the repository at this point in the history
  • Loading branch information
thorio committed Sep 28, 2024
1 parent 19f5f12 commit d4b5c83
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 4 additions & 1 deletion gravel-test-utils/src/xvfb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@ impl Xvfb {
/// Start new Xvfb server with sequential display number.
#[cfg(unix)]
pub fn new() -> Result<Self, io::Error> {
use std::process::Command;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::{process::Command, thread, time::Duration};

static DISPLAY_COUNTER: AtomicUsize = AtomicUsize::new(42);

let display = format!(":{}", DISPLAY_COUNTER.fetch_add(1, Ordering::SeqCst));

let process = Command::new("Xvfb").arg(&display).arg("-ac").spawn()?;

// TODO implement polling/signaling
thread::sleep(Duration::from_millis(1000));

Ok(Self {
process: Some(process),
display,
Expand Down
8 changes: 6 additions & 2 deletions gravel/tests/smoke_test.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(unused_crate_dependencies, clippy::missing_panics_doc)]
#![allow(unused_crate_dependencies, clippy::missing_panics_doc, clippy::print_stderr)]

use gravel_test_utils::xvfb::Xvfb;
use itertools::Itertools;
Expand Down Expand Up @@ -27,10 +27,14 @@ pub fn run_gravel(mut bin: Command, xvfb: Xvfb) {
.env("GRAVEL_CONFIG_PATH", "tests/config")
.env("DISPLAY", xvfb.display())
.arg("--log-file=off")
.arg("-vv")
.output()
.expect("gravel broke");

assert!(output.status.success());
// TODO: capture *and* stream to console
eprintln!("{}", String::from_utf8_lossy(&output.stderr));

assert_eq!(Some(0), output.status.code());

let stderr_string = String::from_utf8(output.stderr).expect("application must output valid UTF-8");

Expand Down

0 comments on commit d4b5c83

Please sign in to comment.