Skip to content

Commit 97193cd

Browse files
committed
tests/unhealthy_database: Ensure that download requests keep working even when the database is unavailable
1 parent ca02f58 commit 97193cd

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/tests/unhealthy_database.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
use crate::builders::CrateBuilder;
12
use crate::util::{RequestHelper, TestApp};
23
use diesel_async::pooled_connection::deadpool::Pool;
34
use diesel_async::AsyncPgConnection;
5+
use googletest::assert_that;
6+
use googletest::matchers::ends_with;
47
use http::StatusCode;
58
use std::time::{Duration, Instant};
69
use tracing::info;
@@ -47,6 +50,27 @@ async fn http_error_with_unhealthy_database() {
4750
assert_eq!(response.status(), StatusCode::OK);
4851
}
4952

53+
#[tokio::test(flavor = "multi_thread")]
54+
async fn download_requests_with_unhealthy_database_succeed() {
55+
let (app, anon, _, token) = TestApp::init().with_chaos_proxy().with_token();
56+
57+
app.db(|conn| {
58+
CrateBuilder::new("foo", token.as_model().user_id)
59+
.version("1.0.0")
60+
.build(conn)
61+
.unwrap();
62+
});
63+
64+
app.primary_db_chaosproxy().break_networking().unwrap();
65+
66+
let response = anon.get::<()>("/api/v1/crates/foo/1.0.0/download").await;
67+
assert_eq!(response.status(), StatusCode::FOUND);
68+
69+
let location = assert_some!(response.headers().get("location"));
70+
let location = assert_ok!(location.to_str());
71+
assert_that!(location, ends_with("/crates/foo/foo-1.0.0.crate"));
72+
}
73+
5074
#[tokio::test(flavor = "multi_thread")]
5175
async fn fallback_to_replica_returns_user_info() {
5276
const URL: &str = "/api/v1/users/foo";

0 commit comments

Comments
 (0)