Skip to content

Commit b74205d

Browse files
authored
Viaduct dependency fixes (#7106)
Removed what I hope are the last remaining `tokio`/`hyper` dependencies in our components: - Updated `ads-client` to use `viaduct-dev` for its integration tests. - Removed the unused `backend-dev` feature from `viaduct`. Also improved the error handling on `viaduct-dev`. If you remove the `#[ignore]` attribute from the ads-client integration tests, they now correctly report that they're failing because they're trying to hit HTTPS endpoints. I think you can re-enable these tests by configuring them to hit `http://ads.allizom.org` instead of `https`.
1 parent ddaf9f9 commit b74205d

File tree

5 files changed

+20
-36
lines changed

5 files changed

+20
-36
lines changed

Cargo.lock

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/ads-client/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ sql-support = { path = "../support/sql" }
3333
mockall = "0.12"
3434
mockito = { version = "0.31", default-features = false }
3535
viaduct-dev = { path = "../support/viaduct-dev" }
36-
viaduct-reqwest = { path = "../support/viaduct-reqwest" }
3736

3837
[build-dependencies]
3938
uniffi = { version = "0.29.0", features = ["build"] }

components/ads-client/tests/integration_test.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use viaduct::Request;
1515
#[test]
1616
#[ignore]
1717
fn test_mock_pocket_billboard_1_placement() {
18-
viaduct_reqwest::use_reqwest_backend();
18+
viaduct_dev::init_backend_dev();
1919

2020
let client = MozAdsClient::new(None);
2121

@@ -25,7 +25,6 @@ fn test_mock_pocket_billboard_1_placement() {
2525
};
2626

2727
let result = client.request_image_ads(vec![placement_request], None);
28-
println!("result: {:?}", result);
2928

3029
assert!(result.is_ok(), "Failed to request ads: {:?}", result.err());
3130

@@ -44,7 +43,7 @@ fn test_mock_pocket_billboard_1_placement() {
4443
#[test]
4544
#[ignore]
4645
fn test_newtab_spocs_placement() {
47-
viaduct_reqwest::use_reqwest_backend();
46+
viaduct_dev::init_backend_dev();
4847

4948
let client = MozAdsClient::new(None);
5049

@@ -56,7 +55,6 @@ fn test_newtab_spocs_placement() {
5655
};
5756

5857
let result = client.request_spoc_ads(vec![placement_request], None);
59-
println!("result: {:?}", result);
6058

6159
assert!(result.is_ok(), "Failed to request ads: {:?}", result.err());
6260

@@ -81,7 +79,7 @@ fn test_newtab_spocs_placement() {
8179
#[test]
8280
#[ignore]
8381
fn test_newtab_tile_1_placement() {
84-
viaduct_reqwest::use_reqwest_backend();
82+
viaduct_dev::init_backend_dev();
8583

8684
let client = MozAdsClient::new(None);
8785

@@ -91,7 +89,6 @@ fn test_newtab_tile_1_placement() {
9189
};
9290

9391
let result = client.request_tile_ads(vec![placement_request], None);
94-
println!("result: {:?}", result);
9592

9693
assert!(result.is_ok(), "Failed to request ads: {:?}", result.err());
9794

@@ -110,7 +107,7 @@ fn test_newtab_tile_1_placement() {
110107
#[test]
111108
#[ignore]
112109
fn test_cache_works_using_real_timeouts() {
113-
viaduct_reqwest::use_reqwest_backend();
110+
viaduct_dev::init_backend_dev();
114111

115112
let cache = HttpCache::builder("integration_tests.db")
116113
.default_ttl(Duration::from_secs(60))

components/support/viaduct-dev/src/lib.rs

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ enum Event {
2929
SendRequest {
3030
request: Request,
3131
settings: ClientSettings,
32-
channel: oneshot::Sender<Response>,
32+
channel: oneshot::Sender<Result<Response>>,
3333
},
3434
Quit,
3535
}
@@ -49,9 +49,10 @@ fn worker_thread(channel: mpsc::Receiver<Event>) {
4949
settings,
5050
channel,
5151
}) => {
52-
if let Err(e) = send_request(request, settings, channel) {
53-
error!("Error sending request: {e}");
54-
}
52+
let result = send_request(request, settings);
53+
channel
54+
.send(result)
55+
.expect("Error sending to oneshot channel");
5556
}
5657
Ok(Event::Quit) => {
5758
info!("Saw Quit event, exiting");
@@ -62,11 +63,7 @@ fn worker_thread(channel: mpsc::Receiver<Event>) {
6263
}
6364

6465
/// Handle `Event::SendRequest`
65-
fn send_request(
66-
request: Request,
67-
settings: ClientSettings,
68-
channel: oneshot::Sender<Response>,
69-
) -> Result<()> {
66+
fn send_request(request: Request, settings: ClientSettings) -> Result<Response> {
7067
let method = match request.method {
7168
Method::Get => minreq::Method::Get,
7269
Method::Head => minreq::Method::Head,
@@ -89,18 +86,15 @@ fn send_request(
8986
.with_timeout(settings.timeout.div_ceil(1000) as u64)
9087
.with_body(request.body.unwrap_or_default());
9188
let mut resp = req.send().map_backend_error()?;
92-
channel
93-
.send(Response {
94-
request_method: request.method,
95-
url: Url::parse(&resp.url)?,
96-
// Use `take` to take all headers, but not partially deconstruct the `Response`.
97-
// This lets us use `into_bytes()` below.
98-
headers: Headers::try_from_hashmap(std::mem::take(&mut resp.headers))?,
99-
status: resp.status_code as u16,
100-
body: resp.into_bytes(),
101-
})
102-
.map_backend_error()?;
103-
Ok(())
89+
Ok(Response {
90+
request_method: request.method,
91+
url: Url::parse(&resp.url)?,
92+
// Use `take` to take all headers, but not partially deconstruct the `Response`.
93+
// This lets us use `into_bytes()` below.
94+
headers: Headers::try_from_hashmap(std::mem::take(&mut resp.headers))?,
95+
status: resp.status_code as u16,
96+
body: resp.into_bytes(),
97+
})
10498
}
10599

106100
/// Initialize the `dev` backend.
@@ -155,6 +149,6 @@ impl Backend for DevBackend {
155149
})
156150
.map_backend_error()?;
157151
// Await the response from the worker thread.
158-
oneshot_rx.await.map_backend_error()
152+
oneshot_rx.await.expect("Error awaiting oneshot channel")
159153
}
160154
}

components/viaduct/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,9 @@ prost = "0.13"
2222
ffi-support = "0.4"
2323
thiserror = "2"
2424
uniffi = { version = "0.29.0" }
25-
tokio = { version = "1", features = ["rt-multi-thread"], optional = true }
26-
hyper = { version = "0.14", features = ["client", "http1", "http2", "tcp"], optional = true }
2725
bhttp = { git = "https://github.com/martinthomson/ohttp.git", rev = "bf6a983845cc0b540effb3a615e92d914dfcfd0b", optional = true }
2826
ohttp = { git = "https://github.com/martinthomson/ohttp.git", rev = "bf6a983845cc0b540effb3a615e92d914dfcfd0b", features = ["client", "server", "app-svc", "external-sqlite"], default-features = false, optional = true }
2927

3028
[features]
3129
default = []
32-
backend-dev = ["dep:tokio", "dep:hyper"]
3330
ohttp = ["dep:bhttp", "dep:ohttp"]

0 commit comments

Comments
 (0)