Implementation:Tensorflow Serving Util Test
| Knowledge Sources | |
|---|---|
| Domains | Testing, Utilities |
| Last Updated | 2026-02-13 00:00 GMT |
Overview
Test suite validating the TensorFlow Serving utility functions used across the serving infrastructure.
Description
This test file validates utility functions defined in tensorflow_serving/servables/tensorflow/util.h. The tests cover input handling utilities (converting Input protos to serialized example tensors), model spec construction helpers, the signature method name check feature toggle, resource estimation from model paths, and collection utilities (map keys, set difference).
The InputUtilTest fixture provides reusable Example factories (example_A, example_B, example_C) for testing InputToSerializedExampleTensor with various input configurations including example lists, example lists with context, and edge cases like duplicate features and missing context.
Usage
Run these tests to validate changes to serving utility functions, particularly input conversion, model spec handling, and resource estimation.
Code Reference
Source Location
- Repository: Tensorflow_Serving
- File: tensorflow_serving/servables/tensorflow/util_test.cc
- Lines: 1-336
Test Fixture
class InputUtilTest : public ::testing::Test {
protected:
Example example_A() {
Feature feature;
feature.mutable_int64_list()->add_value(11);
Example example;
(*example.mutable_features()->mutable_feature())["a"] = feature;
return example;
}
Example example_B();
Example example_C(const int64_t value = 33);
Input input_;
Tensor tensor_;
};
Build Target
bazel test //tensorflow_serving/servables/tensorflow:util_test
Test Coverage
Key Test Cases
| Test Name | Category | Description |
|---|---|---|
| Empty_KindNotSet | Validation | Tests error when input kind is not set |
| Empty_ExampleList | Validation | Tests error on empty example list |
| Empty_ExampleListWithContext | Validation | Tests error on empty example list with context |
| ExampleList | Input Handling | Tests conversion of example list to tensor |
| ExampleListWithContext | Input Handling | Tests conversion with context features merged |
| ExampleListWithOverridingContext | Input Handling | Tests that examples override context features |
| ExampleListWithContext_NoContext | Input Handling | Tests example list with context but no context set |
| ExampleListWithContext_OnlyContext | Input Handling | Tests context only with no examples |
| RequestNumExamplesStreamz | Monitoring | Tests example count monitoring/streamz |
| ExampleCountsTest.Simple | Monitoring | Tests example count tracking |
| ModelSpecTest.NoOptional | Model Spec | Tests model spec with no optional fields |
| ModelSpecTest.OptionalSignature | Model Spec | Tests model spec with optional signature |
| ModelSpecTest.EmptySignature | Model Spec | Tests model spec with empty signature |
| ModelSpecTest.OptionalVersion | Model Spec | Tests model spec with optional version |
| ModelSpecTest.AllOptionalSet | Model Spec | Tests model spec with all optional fields set |
| SignatureMethodNameCheckFeature.SetGet | Feature Toggle | Tests set/get of method name check feature |
| ResourceEstimatorTest | Resource | Tests resource estimation from disk state |
| GetMapKeysTest.GetKeys | Utility | Tests map key extraction |
| SetDifferenceTEST.GetDiff | Utility | Tests set difference computation |
Usage Examples
Test Pattern
TEST_F(InputUtilTest, ExampleList) {
*input_.mutable_example_list()->mutable_examples()->Add() = example_A();
*input_.mutable_example_list()->mutable_examples()->Add() = example_B();
TF_ASSERT_OK(InputToSerializedExampleTensor(input_, &tensor_));
EXPECT_EQ(2, tensor_.NumElements());
const auto vec = tensor_.flat<tstring>();
Example serialized_example;
ASSERT_TRUE(serialized_example.ParseFromString(vec(0)));
EXPECT_THAT(serialized_example, EqualsProto(example_A()));
}