Implementation:Tensorflow Serving Predict Impl Test
| Knowledge Sources | |
|---|---|
| Domains | Testing, Prediction |
| Last Updated | 2026-02-13 00:00 GMT |
Overview
Test suite validating the TensorflowPredictor predict implementation which processes prediction requests through ServerCore.
Description
This test file validates the TensorflowPredictor class which provides the top-level predict API used by the model server. The PredictImplTest fixture sets up two ServerCore instances: one with the half_plus_two SavedModel and another with a counter model. Tests exercise the full prediction pipeline from request validation through model execution to response construction.
Key areas tested include:
- Model spec validation (missing, empty, wrong model name)
- Input tensor validation (empty, mismatched, wrong type)
- Output filter validation (non-existent filters, valid filters)
- Successful prediction with default and named signatures
- Customized signatures for regression and classification
- Model spec override in responses
- Thread pool factory integration
Usage
Run these tests to validate changes to the predict implementation, including request validation, model loading, and response construction.
Code Reference
Source Location
- Repository: Tensorflow_Serving
- File: tensorflow_serving/servables/tensorflow/predict_impl_test.cc
- Lines: 1-481
Test Fixture
class PredictImplTest : public ::testing::Test {
public:
static void SetUpTestSuite() {
TF_ASSERT_OK(CreateServerCore(
test_util::TensorflowTestSrcDirPath(
"cc/saved_model/testdata/half_plus_two"),
&saved_model_server_core_));
TF_ASSERT_OK(CreateServerCore(
test_util::TestSrcDirPath(
"/servables/tensorflow/testdata/saved_model_counter"),
&saved_model_server_core_counter_model_));
}
protected:
ServerCore* GetServerCore() { return saved_model_server_core_.get(); }
ServerCore* GetServerCoreWithCounterModel();
RunOptions GetRunOptions() { return RunOptions(); }
private:
static std::unique_ptr<ServerCore> saved_model_server_core_;
static std::unique_ptr<ServerCore> saved_model_server_core_counter_model_;
};
Build Target
bazel test //tensorflow_serving/servables/tensorflow:predict_impl_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 tensors |
| InputTensorsDontMatchModelSpecInputs | Validation | Tests error on input tensor key mismatch |
| OutputFiltersDontMatchModelSpecOutputs | Validation | Tests error on invalid output filters |
| InputTensorsHaveWrongType | Validation | Tests error on wrong input tensor dtype |
| PredictionSuccess | Integration | Tests successful prediction with half_plus_two model |
| PredictionWithNamedRegressionSignature | Integration | Tests prediction using a named regression signature |
| PredictionWithNamedClassificationSignature | Integration | Tests prediction using a named classification signature |
| PredictionWithCustomizedSignatures | Integration | Tests prediction with custom signature definitions |
| ModelSpecOverride | Integration | Tests model spec version override in response |
| ThreadPoolFactory | Integration | Tests integration with custom thread pool factory |
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;
TensorflowPredictor predictor;
TF_EXPECT_OK(
predictor.Predict(GetRunOptions(), GetServerCore(), request, &response));
// Expected output: 0.5 * 2 + 2 = 3
}