Skip to content

Commit 5e1b48d

Browse files
committed
fix: tests when running without codspeed
1 parent fccae2c commit 5e1b48d

2 files changed

Lines changed: 16 additions & 13 deletions

File tree

crates/codspeed/src/fifo.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use anyhow::bail;
1+
use anyhow::{bail, Context};
22
use nix::libc::O_NONBLOCK;
33
use nix::sys::stat;
44
use nix::unistd::{self, unlink};
@@ -15,18 +15,18 @@ use std::path::{Path, PathBuf};
1515
const RUNNER_CTL_FIFO_NAME: &str = "runner.ctl.fifo";
1616
const RUNNER_ACK_FIFO_NAME: &str = "runner.ack.fifo";
1717

18-
pub fn runner_fifo_dir() -> PathBuf {
19-
let raw_path =
20-
std::env::var("CODSPEED_FIFO_DIR").expect("CODSPEED_FIFO_DIR environment variable not set");
21-
PathBuf::from(raw_path)
18+
pub fn runner_fifo_dir() -> anyhow::Result<PathBuf> {
19+
let raw_path = std::env::var("CODSPEED_FIFO_DIR")
20+
.context("CODSPEED_FIFO_DIR environment variable not set")?;
21+
Ok(PathBuf::from(raw_path))
2222
}
2323

24-
pub fn runner_ctl_fifo_path() -> PathBuf {
25-
runner_fifo_dir().join(RUNNER_CTL_FIFO_NAME)
24+
pub fn runner_ctl_fifo_path() -> anyhow::Result<PathBuf> {
25+
runner_fifo_dir().map(|p| p.join(RUNNER_CTL_FIFO_NAME))
2626
}
2727

28-
pub fn runner_ack_fifo_path() -> PathBuf {
29-
runner_fifo_dir().join(RUNNER_ACK_FIFO_NAME)
28+
pub fn runner_ack_fifo_path() -> anyhow::Result<PathBuf> {
29+
runner_fifo_dir().map(|p| p.join(RUNNER_ACK_FIFO_NAME))
3030
}
3131

3232
#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq)]
@@ -56,6 +56,10 @@ impl BenchGuard {
5656
Ok(instance)
5757
}
5858

59+
pub fn new_with_runner_fifo() -> anyhow::Result<Self> {
60+
Self::new(runner_ctl_fifo_path()?, runner_ack_fifo_path()?)
61+
}
62+
5963
fn send_cmd(&mut self, cmd: Command) -> anyhow::Result<()> {
6064
self.ctl_fifo.send_cmd(cmd)?;
6165
self.ack_fifo.wait_for_ack();
@@ -72,10 +76,10 @@ impl Drop for BenchGuard {
7276
}
7377

7478
pub fn send_cmd(cmd: Command) -> anyhow::Result<()> {
75-
let mut writer = FifoIpc::connect(runner_ctl_fifo_path())?.with_writer()?;
79+
let mut writer = FifoIpc::connect(runner_ctl_fifo_path()?)?.with_writer()?;
7680
writer.send_cmd(cmd).unwrap();
7781

78-
let mut reader = FifoIpc::connect(runner_ack_fifo_path())?.with_reader()?;
82+
let mut reader = FifoIpc::connect(runner_ack_fifo_path()?)?.with_reader()?;
7983
reader.wait_for_ack();
8084

8185
Ok(())

crates/divan_compat/divan_fork/src/bench/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -657,8 +657,7 @@ impl<'a> BenchContext<'a> {
657657

658658
let bench_overheads = timer.bench_overheads();
659659

660-
use codspeed::fifo::*;
661-
let _guard = BenchGuard::new(runner_ctl_fifo_path(), runner_ack_fifo_path());
660+
let _guard = codspeed::fifo::BenchGuard::new_with_runner_fifo();
662661
while {
663662
// Conditions for when sampling is over:
664663
if elapsed_picos >= max_picos {

0 commit comments

Comments
 (0)