Skip to content

Commit f17aa0a

Browse files
authored
chore: fix ci-only flakey telemetry tests (#1383)
Fixes CI-only flakes in telemetry logging E2E tests caused by the non-blocking tracing writer racing with stdout capture. The capture helper now: - waits for pending logs to drain before redirecting stdout - keeps stdout redirected until logs emitted during the request are drained This prevents setup logs from leaking into the capture and request logs from arriving after capture ends. Furthermore, the text logging assertions in the telemetry now count only `router::request` lines, excluding unrelated output from the OTLP test collector that might pollute. Fix was also tested in #1380.
1 parent 0299232 commit f17aa0a

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

e2e/src/telemetry/logging.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,13 @@ async fn test_log_contents_with_just_logging_enabled() {
108108
.capture_stdout_lines()
109109
.await;
110110

111-
assert_eq!(stdout_log.len(), LOG_LINES_BASELINE);
111+
assert_eq!(
112+
stdout_log
113+
.iter()
114+
.filter(|line| line.contains(" router::request:"))
115+
.count(),
116+
LOG_LINES_BASELINE
117+
);
112118
}
113119

114120
#[ntex::test]
@@ -141,7 +147,13 @@ log:
141147
.capture_stdout_lines()
142148
.await;
143149

144-
assert_eq!(stdout_log.len(), LOG_LINES_BASELINE);
150+
assert_eq!(
151+
stdout_log
152+
.iter()
153+
.filter(|line| line.contains(" router::request:"))
154+
.count(),
155+
LOG_LINES_BASELINE
156+
);
145157
}
146158

147159
#[ntex::test]

e2e/src/testkit/stdout.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{future::Future, io::Read};
1+
use std::{future::Future, io::Read, time::Duration};
22

33
use gag::BufferRedirect;
44
use serde_json::{Map, Value};
@@ -15,12 +15,16 @@ impl Default for StdoutLogCapture {
1515

1616
impl StdoutLogCapture {
1717
pub fn new() -> Self {
18+
// let the non-blocking tracing writer finish logs emitted before this capture
19+
std::thread::sleep(Duration::from_millis(50));
1820
Self {
1921
buf: BufferRedirect::stdout().unwrap(),
2022
}
2123
}
2224

2325
pub fn lines(mut self) -> Vec<String> {
26+
// keep stdout redirected until the tracing writer drains this capture's logs
27+
std::thread::sleep(Duration::from_millis(50));
2428
let mut output = String::new();
2529
self.buf.read_to_string(&mut output).unwrap();
2630

0 commit comments

Comments
 (0)