Skip to content

Commit

Permalink
Add test for single item update action cache
Browse files Browse the repository at this point in the history
  • Loading branch information
allada committed Dec 27, 2020
1 parent fcc8a31 commit c3d89e1
Show file tree
Hide file tree
Showing 21 changed files with 480 additions and 47 deletions.
50 changes: 44 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ clap = "2.33.3"
stdext = "0.2.1"
prost-build = "0.6.1"
tonic-build = "0.3.1"
pretty_assertions = "0.6.1"
rustfmt-nightly = "1.4.21"
futures-core = "0.3.8"

Expand Down
2 changes: 2 additions & 0 deletions cas/grpc_service/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ rust_test(
"//proto",
"//third_party:tonic",
"//third_party:tokio",
"//third_party:pretty_assertions",
],
)

Expand All @@ -77,5 +78,6 @@ rust_test(
"//third_party:tonic",
"//third_party:tokio",
"//third_party:prost",
"//third_party:pretty_assertions",
],
)
96 changes: 82 additions & 14 deletions cas/grpc_service/tests/ac_server_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,27 @@ use store::{create_store, Store, StoreType};
const INSTANCE_NAME: &str = "foo";
const HASH1: &str = "0123456789abcdef000000000000000000000000000000000123456789abcdef";

async fn insert_into_store<T: Message>(
store: &dyn Store,
hash: &str,
action_result: &T,
) -> Result<i64, Error> {
let mut store_data = Vec::new();
action_result.encode(&mut store_data)?;
let digest_size = store_data.len() as i64;
store
.update(&hash, store_data.len(), Box::new(Cursor::new(store_data)))
.await?;
Ok(digest_size)
}

#[cfg(test)]
mod get_action_results {
use super::*;
use pretty_assertions::assert_eq; // Must be declared in every module.

use proto::build::bazel::remote::execution::v2::GetActionResultRequest;

async fn insert_into_store<T: Message>(
store: &dyn Store,
hash: &str,
action_result: &T,
) -> Result<i64, Error> {
let mut store_data = Vec::new();
action_result.encode(&mut store_data)?;
let digest_size = store_data.len() as i64;
store
.update(&hash, store_data.len(), Box::new(Cursor::new(store_data)))
.await?;
Ok(digest_size)
}

async fn get_action_result(
ac_server: &AcServer,
hash: &str,
Expand Down Expand Up @@ -105,3 +106,70 @@ mod get_action_results {
Ok(())
}
}

#[cfg(test)]
mod update_action_result {
use super::*;
use pretty_assertions::assert_eq; // Must be declared in every module.

use proto::build::bazel::remote::execution::v2::UpdateActionResultRequest;

fn get_encoded_proto_size<T: Message>(proto: &T) -> Result<usize, Error> {
let mut store_data = Vec::new();
proto.encode(&mut store_data)?;
Ok(store_data.len())
}

async fn update_action_result(
ac_server: &AcServer,
digest: Digest,
action_result: ActionResult,
) -> Result<Response<ActionResult>, Status> {
ac_server
.update_action_result(Request::new(UpdateActionResultRequest {
instance_name: INSTANCE_NAME.to_string(),
action_digest: Some(digest),
action_result: Some(action_result),
results_cache_policy: None,
}))
.await
}

#[tokio::test]
#[ignore]
async fn one_item_update_test() -> Result<(), Error> {
let ac_store = create_store(&StoreType::Memory);
let ac_server = AcServer::new(ac_store.clone(), create_store(&StoreType::Memory));

let mut action_result = ActionResult::default();
action_result.exit_code = 45;

let size_bytes = get_encoded_proto_size(&action_result)?;

let raw_response = update_action_result(
&ac_server,
Digest {
hash: HASH1.to_string(),
size_bytes: size_bytes as i64,
},
action_result.clone(),
)
.await;

assert!(
raw_response.is_ok(),
"Expected success, got error {:?}",
raw_response
);
assert_eq!(raw_response.unwrap().into_inner(), action_result);

let mut raw_data = Vec::new();
ac_store
.get(&HASH1, size_bytes, &mut Cursor::new(&mut raw_data))
.await?;

let decoded_action_result = ActionResult::decode(Cursor::new(&raw_data))?;
assert_eq!(decoded_action_result, action_result);
Ok(())
}
}
4 changes: 4 additions & 0 deletions cas/grpc_service/tests/cas_server_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const BAD_HASH: &str = "BAD_HASH";
#[cfg(test)]
mod find_missing_blobs {
use super::*;
use pretty_assertions::assert_eq; // Must be declared in every module.

use std::io::Cursor;

Expand Down Expand Up @@ -113,6 +114,7 @@ mod find_missing_blobs {
#[cfg(test)]
mod batch_update_blobs {
use super::*;
use pretty_assertions::assert_eq; // Must be declared in every module.

use std::io::Cursor;

Expand Down Expand Up @@ -178,6 +180,7 @@ mod batch_update_blobs {
#[cfg(test)]
mod batch_read_blobs {
use super::*;
use pretty_assertions::assert_eq; // Must be declared in every module.

use std::io::Cursor;

Expand Down Expand Up @@ -268,6 +271,7 @@ mod batch_read_blobs {
#[cfg(test)]
mod end_to_end {
use super::*;
use pretty_assertions::assert_eq; // Must be declared in every module.

use proto::build::bazel::remote::execution::v2::{
batch_update_blobs_request, batch_update_blobs_response, BatchUpdateBlobsRequest,
Expand Down
1 change: 1 addition & 0 deletions cas/store/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@ rust_test(
":traits",
"//third_party:tokio",
"//third_party:tokio_test",
"//third_party:pretty_assertions",
],
)
2 changes: 2 additions & 0 deletions cas/store/tests/memory_store_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#[cfg(test)]
mod memory_store_tests {
use pretty_assertions::assert_eq; // Must be declared in every module.

use std::io::Cursor;
use tokio::io::Error;
use tokio_test::assert_err;
Expand Down
9 changes: 9 additions & 0 deletions third_party/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ alias(
],
)

alias(
name = "pretty_assertions",
actual = "@raze__pretty_assertions__0_6_1//:pretty_assertions",
tags = [
"cargo-raze",
"manual",
],
)

alias(
name = "prost",
actual = "@raze__prost__0_6_1//:prost",
Expand Down
Loading

0 comments on commit c3d89e1

Please sign in to comment.