mirror of
https://github.com/facebook/sapling.git
synced 2024-10-07 07:17:55 +03:00
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:
parent
92b94ab4d0
commit
fef0d8e3fa
@ -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" }
|
||||
|
@ -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(),
|
||||
|
@ -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(())
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user