Skip to content

Commit fe3b4b6

Browse files
committed
test: add agent info endpoint malfunctioning test cases
.NET has test cases which verify the behavior of traces endpoint, that it works even other endpoints could be having problems like config, telemetry or remote config. This PR to add similar level of testing coverage.
1 parent 0957884 commit fe3b4b6

File tree

1 file changed

+85
-4
lines changed
  • data-pipeline/src/trace_exporter

1 file changed

+85
-4
lines changed

data-pipeline/src/trace_exporter/mod.rs

Lines changed: 85 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,7 +1328,7 @@ mod tests {
13281328
r#"{
13291329
"rate_by_service": {
13301330
"service:foo,env:staging": 1.0,
1331-
"service:,env:": 0.8
1331+
"service:,env:": 0.8
13321332
}
13331333
}"#,
13341334
);
@@ -1548,7 +1548,7 @@ mod tests {
15481548
r#"{
15491549
"rate_by_service": {
15501550
"service:foo,env:staging": 1.0,
1551-
"service:,env:": 0.8
1551+
"service:,env:": 0.8
15521552
}
15531553
}"#,
15541554
);
@@ -1580,7 +1580,7 @@ mod tests {
15801580
r#"{
15811581
"rate_by_service": {
15821582
"service:foo,env:staging": 1.0,
1583-
"service:,env:": 0.8
1583+
"service:,env:": 0.8
15841584
}
15851585
}"#
15861586
.to_string()
@@ -1695,7 +1695,7 @@ mod tests {
16951695
let response_body = r#"{
16961696
"rate_by_service": {
16971697
"service:foo,env:staging": 1.0,
1698-
"service:,env:": 0.8
1698+
"service:,env:": 0.8
16991699
}
17001700
}"#;
17011701
let traces_endpoint = server.mock(|when, then| {
@@ -1742,4 +1742,85 @@ mod tests {
17421742
}
17431743
metrics_endpoint.assert_hits(1);
17441744
}
1745+
1746+
#[test]
1747+
#[cfg_attr(miri, ignore)]
1748+
fn test_agent_malfunction_info_4xx() {
1749+
test_agent_malfunction_info(404, r#"{"error":"Not Found"}"#, Duration::from_secs(0));
1750+
}
1751+
1752+
#[test]
1753+
#[cfg_attr(miri, ignore)]
1754+
fn test_agent_malfunction_info_5xx() {
1755+
test_agent_malfunction_info(500, r#"{"error":"Internal Server Error"}"#, Duration::from_secs(0));
1756+
}
1757+
1758+
#[test]
1759+
#[cfg_attr(miri, ignore)]
1760+
fn test_agent_malfunction_info_timeout() {
1761+
test_agent_malfunction_info(408, r#"{"error":"Internal Server Error"}"#, Duration::from_secs(600));
1762+
}
1763+
1764+
#[test]
1765+
#[cfg_attr(miri, ignore)]
1766+
fn test_agent_malfunction_info_wrong_answer() {
1767+
test_agent_malfunction_info(200, "WRONG_ANSWER", Duration::from_secs(0));
1768+
}
1769+
1770+
fn test_agent_malfunction_info(status: u16, response: &str, delay: Duration) {
1771+
let server = MockServer::start();
1772+
1773+
let mock_traces = server.mock(|when, then| {
1774+
when.method(POST)
1775+
.header("Content-type", "application/msgpack")
1776+
.path("/v0.4/traces");
1777+
then.status(200).body(
1778+
r#"{
1779+
"rate_by_service": {
1780+
"service:test,env:staging": 1.0,
1781+
}
1782+
}"#,
1783+
);
1784+
});
1785+
1786+
let mock_info = server.mock(|when, then| {
1787+
when.method(GET).path("/info");
1788+
then.delay(delay).status(status).body(response);
1789+
});
1790+
1791+
let builder = TraceExporterBuilder::default();
1792+
let exporter = builder
1793+
.set_url(&server.url("/"))
1794+
.set_service("test")
1795+
.set_env("staging")
1796+
.set_tracer_version("v0.1")
1797+
.set_language("nodejs")
1798+
.set_language_version("1.0")
1799+
.set_language_interpreter("v8")
1800+
.set_input_format(TraceExporterInputFormat::V04)
1801+
.set_output_format(TraceExporterOutputFormat::V04)
1802+
.enable_stats(Duration::from_secs(10))
1803+
.build()
1804+
.unwrap();
1805+
1806+
let trace_chunk = vec![Span {
1807+
duration: 10,
1808+
..Default::default()
1809+
}];
1810+
1811+
let data = tinybytes::Bytes::from(rmp_serde::to_vec_named(&vec![trace_chunk]).unwrap());
1812+
1813+
// Wait for the info fetcher to get the config
1814+
while mock_info.hits() == 0 {
1815+
exporter.runtime.block_on(async {
1816+
sleep(Duration::from_millis(100)).await;
1817+
})
1818+
}
1819+
1820+
let _ = exporter.send(data, 1).unwrap();
1821+
1822+
exporter.shutdown(None).unwrap();
1823+
1824+
mock_traces.assert();
1825+
}
17451826
}

0 commit comments

Comments
 (0)