Skip to content

Commit b3e01af

Browse files
authored
test(ads-client): remove flaky tests (#7044)
1 parent a4bce2d commit b3e01af

File tree

2 files changed

+2
-96
lines changed

2 files changed

+2
-96
lines changed

components/ads-client/src/instrument.rs

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@ static DEFAULT_TELEMETRY_ENDPOINT: &str = "https://ads.mozilla.org/v1/log";
1515
static TELEMETRY_ENDPONT: LazyLock<RwLock<String>> =
1616
LazyLock::new(|| RwLock::new(DEFAULT_TELEMETRY_ENDPOINT.to_string()));
1717

18-
#[cfg(test)]
19-
pub fn set_telemetry_endpoint(endpoint: String) {
20-
let mut telemetry_endpoint_lock = TELEMETRY_ENDPONT.write();
21-
*telemetry_endpoint_lock = endpoint;
22-
}
23-
2418
fn get_telemetry_endpoint() -> String {
2519
TELEMETRY_ENDPONT.read().clone()
2620
}
@@ -69,51 +63,3 @@ pub fn emit_telemetry_event(event_type: Option<TelemetryEvent>) -> Result<(), Em
6963
}
7064
Ok(())
7165
}
72-
73-
#[cfg(test)]
74-
mod tests {
75-
use super::*;
76-
use crate::error::{CallbackRequestError, ComponentError, RecordClickError};
77-
use mockito::mock;
78-
79-
#[test]
80-
fn test_emit_telemetry_emits_telemetry_for_mappable_error() {
81-
viaduct_dev::init_backend_dev();
82-
set_telemetry_endpoint(format!("{}{}", mockito::server_url(), "/v1/log"));
83-
let mock = mock("GET", "/v1/log")
84-
.match_query(mockito::Matcher::UrlEncoded(
85-
"event".into(),
86-
"\"invalid_url_error\"".into(),
87-
))
88-
.with_status(200)
89-
.expect(1)
90-
.create();
91-
92-
let result: Result<(), ComponentError> = Err(ComponentError::RecordClick(
93-
RecordClickError::CallbackRequest(CallbackRequestError::MissingCallback {
94-
message: "bad url".into(),
95-
}),
96-
));
97-
98-
let res = result.emit_telemetry_if_error();
99-
100-
mock.assert();
101-
102-
assert!(res.is_err());
103-
}
104-
105-
#[test]
106-
fn test_emit_telemetry_event_on_ok_does_nothing() {
107-
viaduct_dev::init_backend_dev();
108-
set_telemetry_endpoint(format!("{}{}", mockito::server_url(), "/v1/log"));
109-
110-
let mock = mock("GET", "/v1/log").with_status(200).expect(0).create();
111-
112-
let result: Result<String, ComponentError> =
113-
Ok("All is good".to_string()).emit_telemetry_if_error();
114-
115-
mock.assert();
116-
assert!(result.is_ok());
117-
assert_eq!(result.unwrap(), "All is good".to_string());
118-
}
119-
}

components/ads-client/src/mars.rs

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,8 @@ impl MARSClient for DefaultMARSClient {
173173
mod tests {
174174

175175
use super::*;
176-
use crate::{
177-
http_cache::CacheMode,
178-
test_utils::{
179-
create_test_client, get_example_happy_ad_response, make_happy_ad_request,
180-
TEST_CONTEXT_ID,
181-
},
176+
use crate::test_utils::{
177+
create_test_client, get_example_happy_ad_response, make_happy_ad_request, TEST_CONTEXT_ID,
182178
};
183179
use mockito::mock;
184180
use url::Host;
@@ -295,42 +291,6 @@ mod tests {
295291
);
296292
}
297293

298-
#[test]
299-
fn test_fetch_ads_cache_policy_respects_refresh() {
300-
viaduct_dev::init_backend_dev();
301-
let expected = get_example_happy_ad_response();
302-
let _m = mock("POST", "/ads")
303-
.with_status(200)
304-
.with_header("content-type", "application/json")
305-
.with_body(serde_json::to_string(&expected).unwrap())
306-
.expect(2) // only first request goes to network
307-
.create();
308-
309-
let client = create_test_client(mockito::server_url());
310-
let ad_request = make_happy_ad_request();
311-
312-
// First call should warm the cache
313-
assert_eq!(
314-
client
315-
.fetch_ads(&ad_request, &RequestCachePolicy::default())
316-
.unwrap(),
317-
expected
318-
);
319-
// Second call should be a network call
320-
assert_eq!(
321-
client
322-
.fetch_ads(
323-
&ad_request,
324-
&RequestCachePolicy {
325-
mode: CacheMode::NetworkFirst,
326-
ttl_seconds: None
327-
}
328-
)
329-
.unwrap(),
330-
expected
331-
);
332-
}
333-
334294
#[test]
335295
fn prod_endpoint_parses_and_is_expected() {
336296
let url = Environment::Prod.into_mars_url();

0 commit comments

Comments
 (0)