Skip to content

Commit fab5c05

Browse files
Add tests to validate monitoring states.
PiperOrigin-RevId: 651882434
1 parent 8cdf0b8 commit fab5c05

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

tensorflow_serving/model_servers/server_core_test.cc

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,14 @@ limitations under the License.
3131
#include "tensorflow/core/lib/random/random.h"
3232
#include "tensorflow/core/lib/strings/stringprintf.h"
3333
#include "tensorflow/core/platform/path.h"
34+
#include "tensorflow/core/platform/types.h"
3435
#include "tensorflow/core/protobuf/error_codes.pb.h"
36+
#include "tsl/lib/core/status_test_util.h"
3537
#include "tensorflow_serving/apis/model.pb.h"
3638
#include "tensorflow_serving/apis/predict.pb.h"
3739
#include "tensorflow_serving/core/request_logger.h"
3840
#include "tensorflow_serving/core/servable_handle.h"
41+
#include "tensorflow_serving/core/servable_id.h"
3942
#include "tensorflow_serving/core/servable_state.h"
4043
#include "tensorflow_serving/core/test_util/availability_test_util.h"
4144
#include "tensorflow_serving/core/test_util/fake_loader_source_adapter.pb.h"
@@ -59,6 +62,8 @@ using ::testing::_;
5962
using ::testing::Invoke;
6063
using ::testing::MockFunction;
6164
using ::testing::NiceMock;
65+
using ::testing::Pair;
66+
using ::testing::UnorderedElementsAre;
6267

6368
TEST_P(ServerCoreTest, PreLoadHook) {
6469
std::unique_ptr<ServerCore> server_core;
@@ -92,6 +97,19 @@ TEST_P(ServerCoreTest, CreateWaitsTillModelsAvailable) {
9297
TF_ASSERT_OK(
9398
server_core->GetServableHandle<string>(model_spec, &servable_handle));
9499
EXPECT_EQ(servable_handle.id(), expected_id);
100+
101+
// Validate monitoring states.
102+
const auto servable_map =
103+
server_core->servable_state_monitor()->GetAllServableStates();
104+
auto it_servable = servable_map.find(test_util::kTestModelName);
105+
ASSERT_NE(it_servable, servable_map.end());
106+
ASSERT_THAT(it_servable->second,
107+
UnorderedElementsAre(Pair(test_util::kTestModelVersion, _)));
108+
const auto state_and_time =
109+
it_servable->second.at(test_util::kTestModelVersion);
110+
EXPECT_TRUE(state_and_time.state.health.ok());
111+
EXPECT_EQ(state_and_time.state.manager_state,
112+
ServableState::ManagerState::kAvailable);
95113
}
96114

97115
TEST_P(ServerCoreTest, ReloadConfigWaitsTillModelsAvailable) {
@@ -128,6 +146,17 @@ TEST_P(ServerCoreTest, ReloadConfigUnloadsModels) {
128146
test_util::WaitUntilServableManagerStateIsOneOf(
129147
*server_core->servable_state_monitor(), servable_id,
130148
{ServableState::ManagerState::kEnd});
149+
// Validate monitoring states.
150+
const auto servable_map =
151+
server_core->servable_state_monitor()->GetAllServableStates();
152+
auto it_servable = servable_map.find(test_util::kTestModelName);
153+
ASSERT_NE(it_servable, servable_map.end());
154+
ASSERT_THAT(it_servable->second,
155+
UnorderedElementsAre(Pair(test_util::kTestModelVersion, _)));
156+
const auto state_and_time =
157+
it_servable->second.at(test_util::kTestModelVersion);
158+
ASSERT_EQ(state_and_time.state.manager_state,
159+
ServableState::ManagerState::kEnd);
131160
}
132161

133162
TEST_P(ServerCoreTest, ReloadConfigHandlesLoadingAPreviouslyUnloadedModel) {
@@ -309,6 +338,21 @@ TEST_P(ServerCoreTest, ErroringModel) {
309338
EXPECT_FALSE(status.ok());
310339
EXPECT_THAT(status.ToString(),
311340
::testing::HasSubstr("1 servable(s) did not become available"));
341+
342+
// Validate monitoring states.
343+
const auto servable_map =
344+
server_core->servable_state_monitor()->GetAllServableStates();
345+
auto it_servable = servable_map.find(test_util::kTestModelName);
346+
ASSERT_NE(it_servable, servable_map.end());
347+
ASSERT_THAT(it_servable->second,
348+
UnorderedElementsAre(Pair(test_util::kTestModelVersion, _)));
349+
const auto state_and_time =
350+
it_servable->second.at(test_util::kTestModelVersion);
351+
EXPECT_EQ(state_and_time.state.health.code(), absl::StatusCode::kCancelled);
352+
EXPECT_THAT(state_and_time.state.health.ToString(),
353+
::testing::HasSubstr("injected error"));
354+
EXPECT_EQ(state_and_time.state.manager_state,
355+
ServableState::ManagerState::kEnd);
312356
}
313357

314358
TEST_P(ServerCoreTest, IllegalReconfigurationToCustomConfig) {

0 commit comments

Comments
 (0)