16 #include "tensorflow_serving/core/test_util/availability_test_util.h"
21 #include "absl/types/optional.h"
22 #include "absl/types/span.h"
23 #include "tensorflow/core/platform/env.h"
25 namespace tensorflow {
33 bool ServableManagerStateIsOneOf(
34 const ServableStateMonitor& monitor,
const ServableId& servable,
35 const std::vector<ServableState::ManagerState>& states) {
36 absl::optional<ServableState> maybe_state = monitor.GetState(servable);
40 const ServableState state = *maybe_state;
42 for (
const ServableState::ManagerState& desired_manager_state : states) {
43 if (state.manager_state == desired_manager_state) {
52 void WaitUntilServableManagerStateIsOneOf(
53 const ServableStateMonitor& monitor,
const ServableId& servable,
54 const std::vector<ServableState::ManagerState>& states) {
55 while (!ServableManagerStateIsOneOf(monitor, servable, states)) {
56 Env::Default()->SleepForMicroseconds(50 * 1000 );
60 void WaitUntilVersionsAvailable(
61 const ServableStateMonitor& monitor,
const string& servable_id_name,
62 absl::Span<const int64_t> servable_id_versions) {
63 for (int64_t version : servable_id_versions) {
64 const ServableId servable_id = {servable_id_name, version};
65 WaitUntilServableManagerStateIsOneOf(
66 monitor, servable_id, {ServableState::ManagerState::kAvailable});