|
| 1 | +use crate::builders::CrateBuilder; |
1 | 2 | use crate::util::{RequestHelper, TestApp}; |
2 | 3 | use diesel_async::pooled_connection::deadpool::Pool; |
3 | 4 | use diesel_async::AsyncPgConnection; |
| 5 | +use googletest::assert_that; |
| 6 | +use googletest::matchers::ends_with; |
4 | 7 | use http::StatusCode; |
5 | 8 | use std::time::{Duration, Instant}; |
6 | 9 | use tracing::info; |
@@ -47,6 +50,27 @@ async fn http_error_with_unhealthy_database() { |
47 | 50 | assert_eq!(response.status(), StatusCode::OK); |
48 | 51 | } |
49 | 52 |
|
| 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 | + |
50 | 74 | #[tokio::test(flavor = "multi_thread")] |
51 | 75 | async fn fallback_to_replica_returns_user_info() { |
52 | 76 | const URL: &str = "/api/v1/users/foo"; |
|
0 commit comments