Implementation:Tensorflow Serving Predict Util Test
| Knowledge Sources | |
|---|---|
| Domains | Testing, Prediction |
| Last Updated | 2026-02-13 00:00 GMT |
Overview
Test suite validating the predict utility functions including RunPredict which executes prediction directly on a SavedModelBundle.
Description
This test file validates the lower-level predict utility functions that operate directly on SavedModelBundle instances rather than going through ServerCore. The PredictImplTest fixture creates multiple ServerCore instances (including one with a "bad" model for error testing) and obtains ServableHandle<SavedModelBundle> to call RunPredict directly. A FakeSession is also provided for isolated unit testing that copies input tensors to output.
Key areas tested include:
- Model spec validation (missing, empty, not found)
- Input tensor validation (empty, mismatched, wrong type, invalid tensor)
- Output filter validation
- Model with missing signatures
- Successful prediction with various signature types
- Customized signature handling
- Thread pool options propagation
- Method name checking feature
Usage
Run these tests to validate changes to the RunPredict utility function and related prediction helpers.
Code Reference
Source Location
- Repository: Tensorflow_Serving
- File: tensorflow_serving/servables/tensorflow/predict_util_test.cc
- Lines: 1-614
Test Fixture
class FakeSession : public tensorflow::Session {
public:
// Copies input tensors to output for testing
absl::Status Run(const RunOptions& run_options,
const std::vector<std::pair<string, Tensor>>& inputs,
const std::vector<string>& output_names,
const std::vector<string>& target_nodes,
std::vector<Tensor>* outputs,
RunMetadata* run_metadata,
const thread::ThreadPoolOptions& thread_pool_options) override;
};
class PredictImplTest : public ::testing::Test {
protected:
absl::Status CallPredict(ServerCore* server_core,
const PredictRequest& request,
PredictResponse* response,
const thread::ThreadPoolOptions& opts = {});
};
Build Target
bazel test //tensorflow_serving/servables/tensorflow:predict_util_test
Test Coverage
Key Test Cases
| Test Name | Category | Description |
|---|---|---|
| MissingOrEmptyModelSpec | Validation | Tests error on missing or empty model spec |
| EmptyInputList | Validation | Tests error on empty input list |
| InputTensorsDontMatchModelSpecInputs | Validation | Tests error on input tensor mismatch |
| PredictionInvalidTensor | Validation | Tests error on invalid tensor data |
| OutputFiltersDontMatchModelSpecOutputs | Validation | Tests error on invalid output filters |
| InputTensorsHaveWrongType | Validation | Tests error on wrong tensor dtype |
| ModelMissingSignatures | Error Handling | Tests error when model has no signatures |
| PredictionSuccess | Integration | Tests successful prediction execution |
| PredictionWithNamedRegressionSignature | Integration | Tests prediction with named regression signature |
| PredictionWithNamedClassificationSignature | Integration | Tests prediction with named classification signature |
| PredictionWithCustomizedSignatures | Integration | Tests prediction with custom signatures |
| ThreadPoolOptions | Integration | Tests thread pool options are passed through |
| MethodNameCheck | Feature Toggle | Tests method name checking feature |
Usage Examples
Test Pattern
TEST_F(PredictImplTest, PredictionSuccess) {
PredictRequest request;
PredictResponse response;
ModelSpec* model_spec = request.mutable_model_spec();
model_spec->set_name(kTestModelName);
model_spec->mutable_version()->set_value(kTestModelVersion);
TensorProto tensor_proto;
tensor_proto.add_float_val(2.0);
tensor_proto.set_dtype(tensorflow::DT_FLOAT);
(*request.mutable_inputs())[kInputTensorKey] = tensor_proto;
TF_EXPECT_OK(CallPredict(GetServerCore(), request, &response));
// Validates model spec and output tensor in response
}