Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Tensorflow Serving Regressor Test

From Leeroopedia
Knowledge Sources
Domains Testing, Regression
Last Updated 2026-02-13 00:00 GMT

Overview

Test suite validating the TensorFlow Serving regressor servable, which handles regression inference requests.

Description

This test file provides comprehensive coverage of the TensorFlowRegressor implementation. It uses a FakeSession that simulates a TensorFlow session by parsing serialized Example protos from input tensors and producing regression output values. The RegressorTest parameterized fixture validates regression with example lists, context, named signatures, error handling for malformed inputs, and correctness of output tensor shapes and types.

Key areas tested include:

  • Basic regression with example lists and example lists with context
  • Valid and invalid named signature handling
  • Error cases: malformed outputs, empty inputs, session run failures
  • Output tensor validation: unexpected size, unexpected type, improperly sized outputs
  • Missing regression signature handling
  • Method name checking feature toggle

Usage

Run these tests to validate changes to the regressor servable, signature handling, or input/output tensor processing for regression tasks.

Code Reference

Source Location

  • Repository: Tensorflow_Serving
  • File: tensorflow_serving/servables/tensorflow/regressor_test.cc
  • Lines: 1-593

Test Fixture

class FakeSession : public tensorflow::Session {
 public:
  explicit FakeSession(absl::optional<int64_t> expected_timeout)
      : expected_timeout_(expected_timeout) {}
  // Parses Examples from input tensors and produces regression outputs
  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& options) override;
};

class RegressorTest : public ::testing::TestWithParam<bool> {
  // Parameterized on method name check enabled/disabled
};

Build Target

bazel test //tensorflow_serving/servables/tensorflow:regressor_test

Test Coverage

Key Test Cases

Test Name Category Description
BasicExampleList Input Handling Tests regression with a standard example list
BasicExampleListWithContext Input Handling Tests regression with example list and context
ValidNamedSignature Signature Tests regression with a valid named signature
InvalidNamedSignature Error Handling Tests error on invalid named signature
MalformedOutputs Error Handling Tests error on improperly sized output tensors
EmptyInput Error Handling Tests error on empty input
EmptyExampleList Error Handling Tests error on empty example list
EmptyExampleListWithContext Error Handling Tests error on empty example list with context
RunsFails Error Handling Tests handling of session Run failures
UnexpectedOutputTensorSize Validation Tests error on mismatched output tensor batch size
UnexpectedOutputTensorType Validation Tests error on incorrect output tensor type
MissingRegressionSignature Error Handling Tests error when regression signature is missing
MethodNameCheck Feature Toggle Tests method name checking feature toggle

Usage Examples

Test Pattern

TEST_P(RegressorTest, BasicExampleList) {
  auto* examples =
      request_.mutable_input()->mutable_example_list()->mutable_examples();
  *examples->Add() = example({{"output", 2.0}});
  *examples->Add() = example({{"output", 3.0}});

  RegressionResult result;
  TF_ASSERT_OK(regressor_->Regress(request_, &result));
  EXPECT_THAT(result, EqualsProto(expected_result));
}

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment