Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Tensorflow Serving Simple Loader Test

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

Overview

Test suite validating the SimpleLoader component, which provides a lightweight mechanism for loading and unloading servable objects with resource estimation.

Description

This test file exercises the SimpleLoader template class and the SimpleLoaderSourceAdapter. It uses a type-parameterized test fixture (SimpleLoaderTest) instantiated with both LoaderCreatorWithoutMetadata and LoaderCreatorWithMetadata to verify that loading works with and without metadata. A helper Caller class tracks lifecycle states (construction, usage, destruction). Tests cover servable state transitions, resource estimation before and after load, post-load resource release, load errors, and the source adapter for converting servable data into loaders.

Usage

Run these tests to validate that SimpleLoader correctly manages servable lifecycles, reports resource estimates accurately, handles load failures gracefully, and that the source adapter correctly bridges servable data to loader instances.

Code Reference

Source Location

  • Repository: Tensorflow_Serving
  • File: tensorflow_serving/core/simple_loader_test.cc
  • Lines: 1-343

Test Fixture

template <typename T>
class SimpleLoaderTest : public ::testing::Test {};
using LoaderCreatorTypes =
    ::testing::Types<LoaderCreatorWithoutMetadata, LoaderCreatorWithMetadata>;
TYPED_TEST_SUITE(SimpleLoaderTest, LoaderCreatorTypes);

Build Target

bazel test //tensorflow_serving/core:simple_loader_test

Test Coverage

Key Test Cases

Test Name Category Description
VerifyServableStates Lifecycle Moves a loader through its full lifetime verifying the servable state at each step
ResourceEstimation Resources Validates resource estimation returns correct values before and after load
ResourceEstimationWithPostLoadRelease Resources Tests resource estimate reduction after post-load resource release
LoadError Error Handling Ensures load errors are propagated and servable is null after failure
WithoutMetadata (Compatibility) Compatibility Tests SimpleLoader creation without metadata support
WithMetadata (Compatibility) Compatibility Tests SimpleLoader creation with metadata and verifies metadata is passed correctly
Basic (SourceAdapter) Adapter Tests SimpleLoaderSourceAdapter converts servable data to loader correctly
OkayToDeleteAdapter (SourceAdapter) Lifecycle Verifies adapter can be deleted while created loaders remain valid

Usage Examples

Test Pattern

TYPED_TEST(SimpleLoaderTest, VerifyServableStates) {
  State state = State::kNone;
  auto loader = TypeParam::template CreateSimpleLoader<Caller>(
      [&state](std::unique_ptr<Caller>* caller) {
        caller->reset(new Caller(&state));
        return absl::OkStatus();
      },
      SimpleLoader<Caller>::EstimateNoResources());
  EXPECT_EQ(State::kNone, state);
  const absl::Status status = TypeParam::Load(loader.get());
  TF_EXPECT_OK(status);
  EXPECT_EQ(State::kCtor, state);
  AnyPtr servable = loader->servable();
  ASSERT_TRUE(servable.get<Caller>() != nullptr);
  servable.get<Caller>()->DoStuff();
  EXPECT_EQ(State::kDoStuff, state);
  loader->Unload();
  EXPECT_EQ(State::kDtor, state);
}

Related Pages

Page Connections

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