Skip to content

Commit

Permalink
fix: fix test of prometheus
Browse files Browse the repository at this point in the history
  • Loading branch information
vicanso committed Dec 22, 2024
1 parent fefb2f3 commit 4e39e26
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/state/prom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -663,16 +663,18 @@ pub fn new_prometheus(server: &str) -> Result<Prometheus> {

#[cfg(test)]
mod tests {
use std::time::Duration;

use super::new_prometheus;
use crate::{
config::LocationConf,
proxy::Location,
state::{CompressionStat, State},
util,
};
use http::StatusCode;
use pingora::proxy::Session;
use pretty_assertions::assert_eq;
use std::sync::Arc;
use std::time::Duration;
use tokio_test::io::Builder;

#[tokio::test]
Expand All @@ -696,6 +698,15 @@ mod tests {
let p = new_prometheus("pingap").unwrap();
p.before("");

let lo = Location::new(
"lo",
&LocationConf {
upstream: Some("upstream".to_string()),
..Default::default()
},
)
.unwrap();

p.after(
&session,
&State {
Expand All @@ -716,10 +727,11 @@ mod tests {
out_bytes: 512,
duration: Duration::from_millis(20),
}),
location: Some(Arc::new(lo)),
..Default::default()
},
);
let buf = p.metrics().unwrap();
assert_eq!(186, std::str::from_utf8(&buf).unwrap().split('\n').count());
assert_eq!(221, std::str::from_utf8(&buf).unwrap().split('\n').count());
}
}

0 comments on commit 4e39e26

Please sign in to comment.