Skip to content

Commit 5c82629

Browse files
authored
test: add agent info endpoint malfunctioning test cases (#891)
* 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. * fix format
1 parent eb23407 commit 5c82629

File tree

1 file changed

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

1 file changed

+93
-4
lines changed

data-pipeline/src/trace_exporter/mod.rs

Lines changed: 93 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,93 @@ 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(
1756+
500,
1757+
r#"{"error":"Internal Server Error"}"#,
1758+
Duration::from_secs(0),
1759+
);
1760+
}
1761+
1762+
#[test]
1763+
#[cfg_attr(miri, ignore)]
1764+
fn test_agent_malfunction_info_timeout() {
1765+
test_agent_malfunction_info(
1766+
408,
1767+
r#"{"error":"Internal Server Error"}"#,
1768+
Duration::from_secs(600),
1769+
);
1770+
}
1771+
1772+
#[test]
1773+
#[cfg_attr(miri, ignore)]
1774+
fn test_agent_malfunction_info_wrong_answer() {
1775+
test_agent_malfunction_info(200, "WRONG_ANSWER", Duration::from_secs(0));
1776+
}
1777+
1778+
fn test_agent_malfunction_info(status: u16, response: &str, delay: Duration) {
1779+
let server = MockServer::start();
1780+
1781+
let mock_traces = server.mock(|when, then| {
1782+
when.method(POST)
1783+
.header("Content-type", "application/msgpack")
1784+
.path("/v0.4/traces");
1785+
then.status(200).body(
1786+
r#"{
1787+
"rate_by_service": {
1788+
"service:test,env:staging": 1.0,
1789+
}
1790+
}"#,
1791+
);
1792+
});
1793+
1794+
let mock_info = server.mock(|when, then| {
1795+
when.method(GET).path("/info");
1796+
then.delay(delay).status(status).body(response);
1797+
});
1798+
1799+
let builder = TraceExporterBuilder::default();
1800+
let exporter = builder
1801+
.set_url(&server.url("/"))
1802+
.set_service("test")
1803+
.set_env("staging")
1804+
.set_tracer_version("v0.1")
1805+
.set_language("nodejs")
1806+
.set_language_version("1.0")
1807+
.set_language_interpreter("v8")
1808+
.set_input_format(TraceExporterInputFormat::V04)
1809+
.set_output_format(TraceExporterOutputFormat::V04)
1810+
.enable_stats(Duration::from_secs(10))
1811+
.build()
1812+
.unwrap();
1813+
1814+
let trace_chunk = vec![Span {
1815+
duration: 10,
1816+
..Default::default()
1817+
}];
1818+
1819+
let data = tinybytes::Bytes::from(rmp_serde::to_vec_named(&vec![trace_chunk]).unwrap());
1820+
1821+
// Wait for the info fetcher to get the config
1822+
while mock_info.hits() == 0 {
1823+
exporter.runtime.block_on(async {
1824+
sleep(Duration::from_millis(100)).await;
1825+
})
1826+
}
1827+
1828+
let _ = exporter.send(data, 1).unwrap();
1829+
1830+
exporter.shutdown(None).unwrap();
1831+
1832+
mock_traces.assert();
1833+
}
17451834
}

0 commit comments

Comments
 (0)