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 Aspired Versions Manager Test

From Leeroopedia
Revision as of 13:52, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Tensorflow_Serving_Aspired_Versions_Manager_Test.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains Testing, Core Management
Last Updated 2026-02-13 00:00 GMT

Overview

Test suite validating the AspiredVersionsManager which manages servable lifecycle based on aspired version sets and version policies.

Description

This test file exercises the AspiredVersionsManager class, the central component that manages loading, unloading, and transitioning of servable versions based on aspired version callbacks and pluggable version policies. The AspiredVersionsManagerTest fixture is parameterized on thread pool sizes (inline vs. threaded load/unload) and the enable_reload_servables_with_error flag. It sets up two servable streams with two versions each, using FakeLoader, MockLoader, EventBus, and ServableStateMonitor for comprehensive state tracking. Tests use AspiredVersionsManagerTestAccess to manually trigger policy actions.

Usage

Run these tests to verify correct servable lifecycle management: loading, unloading, error handling, retry logic, event bus notifications, version reversion, and custom sort actions. Essential after changes to the manager, version policies, or loader harness integration.

Code Reference

Source Location

  • Repository: Tensorflow_Serving
  • File: tensorflow_serving/core/aspired_versions_manager_test.cc
  • Lines: 1-1387

Test Fixture

struct ThreadPoolSizes {
  uint64_t num_load_threads;
  uint64_t num_unload_threads;
};

class AspiredVersionsManagerTest
    : public ::testing::TestWithParam<std::tuple<ThreadPoolSizes, bool>> {
 protected:
  AspiredVersionsManagerTest()
      : servable_event_bus_(EventBus<ServableState>::CreateEventBus()),
        servable_state_monitor_(servable_event_bus_.get()),
        thread_pool_sizes_(std::get<0>(GetParam())),
        enable_reload_servables_with_error_(std::get<1>(GetParam())) {
    AspiredVersionsManager::Options manager_options;
    manager_options.num_load_threads = thread_pool_sizes_.num_load_threads;
    manager_options.num_unload_threads = thread_pool_sizes_.num_unload_threads;
    manager_options.manage_state_interval_micros = -1;
    manager_options.aspired_version_policy.reset(
        new AvailabilityPreservingPolicy());
    manager_options.servable_event_bus = servable_event_bus_.get();
    manager_options.max_num_load_retries = max_num_load_retries_;
    TF_CHECK_OK(AspiredVersionsManager::Create(
        std::move(manager_options), &manager_));
  }

  void SetUp() override {
    // Sets up two servable streams (kServableName, kServableName2)
    // each with versions 0 and 1, all loaded and available
  }

  std::shared_ptr<EventBus<ServableState>> servable_event_bus_;
  ServableStateMonitor servable_state_monitor_;
  ThreadPoolSizes thread_pool_sizes_;
  bool enable_reload_servables_with_error_;
  std::unique_ptr<AspiredVersionsManager> manager_;
};

Build Target

bazel test //tensorflow_serving/core:aspired_versions_manager_test

Test Coverage

Key Test Cases

Test Name Category Description
ServableHandleNotFoundMissingLoaderName Error Handling Verifies NOT_FOUND for a non-existent servable name
ServableHandleNotFoundMissingVersion Error Handling Verifies NOT_FOUND for a non-existent version
ServableHandleInvalidArgument Validation Tests INVALID_ARGUMENT when requesting with wrong type
ServableHandleLatest Handle Retrieval Verifies latest version handle retrieval
ServableHandleLatestVersionIsZero Handle Retrieval Tests handle retrieval when the latest version is 0
ReloadAspiredError Error Recovery Tests reloading behavior for servables in error state
ServableHandleSpecificVersion Handle Retrieval Verifies retrieval of a specific version handle
ListAvailableServableIds Listing Tests listing of all available servable IDs
GetAvailableServableHandles Handle Retrieval Validates bulk retrieval of available handles
AspiredRemovedFull Lifecycle Tests full removal of all aspired versions for a servable
AspiredRemovedPartial Lifecycle Tests partial removal of aspired versions
RevertToSmallerVersionNumber Lifecycle Validates reverting to a smaller version number
AspiredAndManageStateLoad Policy Tests aspired versions callback triggering loads via policy
AspiredAndManageStateUnload Policy Tests aspired versions callback triggering unloads via policy
ManagerPrefersUnloadOverLoad Policy Verifies manager prioritizes unloads over loads
CustomSortActions Policy Tests custom action sorting in the version policy
ErroneousAspiredVersion Error Handling Tests handling of aspired versions with errors
DestructOnNonServingThread Lifecycle Ensures safe destruction from a non-serving thread
EventBusServableLifecycle Events Validates full lifecycle events on the event bus
RetryOnLoadErrorFinallySucceeds Retry Tests retry logic that eventually succeeds
RetryOnLoadErrorFinallyFails Retry Tests retry logic that eventually fails
UnaspireThenImmediatelyReaspire Lifecycle Tests rapid un-aspire and re-aspire sequence
CallPolicyWithAllVersions Policy Verifies the policy is called with all version information

Usage Examples

Test Pattern

// Creates an aspired-versions entry with 'id' and a FakeLoader
// whose servable is id.version.
ServableData<std::unique_ptr<Loader>> CreateAspiredVersion(
    const ServableId& id) {
  std::unique_ptr<Loader> loader(new FakeLoader(id.version));
  return CreateServableData(id, std::move(loader));
}

TEST_P(AspiredVersionsManagerTest, ServableHandleLatest) {
  ServableHandle<int64_t> handle;
  TF_ASSERT_OK(manager_->GetServableHandle(
      ServableRequest::Latest(kServableName), &handle));
  EXPECT_EQ(kNumVersionsPerServable - 1, *handle);
}

Related Pages

Page Connections

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