-
-
Notifications
You must be signed in to change notification settings - Fork 644
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prepare remote::remote_cache::CommandRunner for other providers (#19459)
This does preparatory refactoring towards #11149, by adjusting `remote::remote_cache::CommandRunner` in a few ways to make it easier to plop in new 'providers': - package the various options for creating a provider/command runner into structs, and a bunch of mechanical refactoring to use those structs - explicit tests for the REAPI provider This continues #19424, but, unlike that one, doesn't refactor `remote_cache_tests.rs` to (mostly) use in-memory providers, as those tests are significantly more complicated, with many more services than just the get/update caching provider and I don't think it strictly blocks #11149. After this, the next steps towards #11149 will be: 1. implement new providers, with some sort of factory function for constructing the appropriate provider 2. expose settings in `pants.toml` to select and configure those new providers
- Loading branch information
Showing
7 changed files
with
281 additions
and
106 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
123 changes: 123 additions & 0 deletions
123
src/rust/engine/process_execution/remote/src/remote_cache/reapi_tests.rs
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,123 @@ | ||
// Copyright 2023 Pants project contributors (see CONTRIBUTORS.md). | ||
// Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
use std::{collections::BTreeMap, time::Duration}; | ||
|
||
use hashing::Digest; | ||
use mock::StubCAS; | ||
use process_execution::Context; | ||
use protos::gen::build::bazel::remote::execution::v2 as remexec; | ||
|
||
use super::{reapi::Provider, ActionCacheProvider, RemoteCacheProviderOptions}; | ||
|
||
fn new_provider(cas: &StubCAS) -> Provider { | ||
Provider::new(RemoteCacheProviderOptions { | ||
instance_name: None, | ||
action_cache_address: cas.address(), | ||
root_ca_certs: None, | ||
headers: BTreeMap::new(), | ||
concurrency_limit: 256, | ||
rpc_timeout: Duration::from_secs(2), | ||
}) | ||
.unwrap() | ||
} | ||
|
||
#[tokio::test] | ||
async fn get_action_result_existing() { | ||
let cas = StubCAS::empty(); | ||
let provider = new_provider(&cas); | ||
|
||
let action_digest = Digest::of_bytes(b"get_action_cache test"); | ||
let action_result = remexec::ActionResult { | ||
exit_code: 123, | ||
..Default::default() | ||
}; | ||
cas | ||
.action_cache | ||
.action_map | ||
.lock() | ||
.insert(action_digest.hash, action_result.clone()); | ||
|
||
assert_eq!( | ||
provider | ||
.get_action_result(action_digest, &Context::default()) | ||
.await, | ||
Ok(Some(action_result)) | ||
); | ||
} | ||
|
||
#[tokio::test] | ||
async fn get_action_result_missing() { | ||
let cas = StubCAS::empty(); | ||
let provider = new_provider(&cas); | ||
|
||
let action_digest = Digest::of_bytes(b"update_action_cache test"); | ||
|
||
assert_eq!( | ||
provider | ||
.get_action_result(action_digest, &Context::default()) | ||
.await, | ||
Ok(None) | ||
); | ||
} | ||
|
||
#[tokio::test] | ||
async fn get_action_result_grpc_error() { | ||
let cas = StubCAS::builder().ac_always_errors().build(); | ||
let provider = new_provider(&cas); | ||
|
||
let action_digest = Digest::of_bytes(b"get_action_result_grpc_error test"); | ||
|
||
let error = provider | ||
.get_action_result(action_digest, &Context::default()) | ||
.await | ||
.expect_err("Want err"); | ||
|
||
assert!( | ||
error.contains("unavailable"), | ||
"Bad error message, got: {error}" | ||
); | ||
} | ||
|
||
#[tokio::test] | ||
async fn update_action_cache() { | ||
let cas = StubCAS::empty(); | ||
let provider = new_provider(&cas); | ||
|
||
let action_digest = Digest::of_bytes(b"update_action_cache test"); | ||
let action_result = remexec::ActionResult { | ||
exit_code: 123, | ||
..Default::default() | ||
}; | ||
|
||
provider | ||
.update_action_result(action_digest, action_result.clone()) | ||
.await | ||
.unwrap(); | ||
|
||
assert_eq!( | ||
cas.action_cache.action_map.lock()[&action_digest.hash], | ||
action_result | ||
); | ||
} | ||
|
||
#[tokio::test] | ||
async fn update_action_cache_grpc_error() { | ||
let cas = StubCAS::builder().ac_always_errors().build(); | ||
let provider = new_provider(&cas); | ||
|
||
let action_digest = Digest::of_bytes(b"update_action_cache_grpc_error test"); | ||
let action_result = remexec::ActionResult { | ||
exit_code: 123, | ||
..Default::default() | ||
}; | ||
|
||
let error = provider | ||
.update_action_result(action_digest, action_result.clone()) | ||
.await | ||
.expect_err("Want err"); | ||
|
||
assert!( | ||
error.contains("unavailable"), | ||
"Bad error message, got: {error}" | ||
); | ||
} |
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
Oops, something went wrong.