-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ENG-7377] Block storage access if backend not running (#30127)
GitOrigin-RevId: 589909c731163f8e4ccb1195997a6a5c7d0cf506
- Loading branch information
Showing
3 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use common::{ | ||
components::ComponentId, | ||
types::BackendState, | ||
}; | ||
use errors::ErrorMetadataAnyhowExt; | ||
use futures::stream; | ||
use keybroker::Identity; | ||
use model::backend_state::BackendStateModel; | ||
use runtime::testing::TestRuntime; | ||
|
||
use crate::{ | ||
test_helpers::ApplicationTestExt, | ||
Application, | ||
}; | ||
|
||
#[convex_macro::test_runtime] | ||
pub(crate) async fn test_backend_not_running_cannot_store_file( | ||
rt: TestRuntime, | ||
) -> anyhow::Result<()> { | ||
let app = Application::new_for_tests(&rt).await?; | ||
|
||
let file_body = Box::pin(stream::once(async { | ||
Ok(bytes::Bytes::from(vec![55; 1024 + 1])) | ||
})); | ||
let ok_result = app | ||
.store_file(ComponentId::Root, None, None, None, file_body) | ||
.await; | ||
assert!(ok_result.is_ok()); | ||
|
||
let mut tx = app.begin(Identity::system()).await?; | ||
BackendStateModel::new(&mut tx) | ||
.toggle_backend_state(BackendState::Disabled) | ||
.await?; | ||
app.commit_test(tx).await?; | ||
let file_body = Box::pin(stream::once(async { | ||
Ok(bytes::Bytes::from(vec![55; 1024 + 1])) | ||
})); | ||
let result = app | ||
.store_file(ComponentId::Root, None, None, None, file_body) | ||
.await; | ||
assert!(result.is_err()); | ||
let error = result.unwrap_err(); | ||
assert!(error.is_bad_request()); | ||
assert_eq!(error.short_msg(), "BackendIsNotRunning"); | ||
Ok(()) | ||
} |