mononoke: lfs: Test the result of upload when a blobstore is failing

Summary:
D35892336 (9b18b0d3be) fixed a bug in the LFS server that meant it would consider
an upload successful, even if writing to internal stores failed.

Add a test that verifies writing to a failing blobstore results in upload
failure.

Reviewed By: mitrandir77

Differential Revision: D35928308

fbshipit-source-id: 296ccdddb6f4b86f5fb778f97185a8a6a0ea9d17
This commit is contained in:
Harvey Hunt 2022-04-27 13:46:35 -07:00 committed by Facebook GitHub Bot
parent 92b94ab4d0
commit fef0d8e3fa
3 changed files with 42 additions and 1 deletions

View File

@ -57,6 +57,7 @@ time_window_counter = { version = "0.1.0", path = "../time_window_counter" }
tokio = { version = "1.15", features = ["full", "test-util", "tracing"] }
[dev-dependencies]
chaosblob = { version = "0.1.0", path = "../blobstore/chaosblob" }
fbinit-tokio = { version = "0.1.0", git = "https://github.com/facebookexperimental/rust-shed.git", branch = "main" }
memblob = { version = "0.1.0", path = "../blobstore/memblob" }
mononoke_types-mocks = { version = "0.1.0", path = "../mononoke_types/mocks" }

View File

@ -603,9 +603,18 @@ mod test {
impl RepositoryRequestContext {
pub fn test_builder(fb: FacebookInit) -> Result<TestContextBuilder<'static>, Error> {
let repo = TestRepoFactory::new(fb)?.build()?;
Self::test_builder_with_repo(fb, repo)
}
pub fn test_builder_with_repo(
fb: FacebookInit,
repo: BlobRepo,
) -> Result<TestContextBuilder<'static>, Error> {
Ok(TestContextBuilder {
fb,
repo: TestRepoFactory::new(fb)?.build()?,
repo,
self_uris: vec!["http://foo.com/"],
upstream_uri: Some("http://bar.com".to_string()),
config: ServerConfig::default(),

View File

@ -426,8 +426,13 @@ pub async fn upload(state: &mut State) -> Result<impl TryIntoResponse, HttpError
#[cfg(test)]
mod test {
use super::*;
use chaosblob::{ChaosBlobstore, ChaosOptions};
use fbinit::FacebookInit;
use futures::{future, stream};
use memblob::Memblob;
use std::num::NonZeroU32;
use std::sync::Arc;
use test_repo_factory::TestRepoFactory;
#[fbinit::test]
async fn test_upload_from_client_discard_upstream(fb: FacebookInit) -> Result<(), Error> {
@ -444,4 +449,30 @@ mod test {
Ok(())
}
#[fbinit::test]
async fn test_upload_from_client_failing_internal(fb: FacebookInit) -> Result<(), Error> {
// Create a test repo with a blobstore that fails all reads and writes.
let repo = TestRepoFactory::new(fb)?
.with_blobstore(Arc::new(ChaosBlobstore::new(
Memblob::default(),
ChaosOptions::new(NonZeroU32::new(1), NonZeroU32::new(1)),
)))
.build()?;
let ctx = RepositoryRequestContext::test_builder_with_repo(fb, repo)?
.upstream_uri(None)
.build()?;
let body = stream::once(future::ready(Ok(Bytes::from("foobar"))));
let oid =
Sha256::from_str("c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2")?;
let size = 6;
let r = upload_from_client(&ctx, oid, size, body, &mut None).await;
assert!(r.is_err());
Ok(())
}
}