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 File System Storage Path Source Test

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

Overview

Test suite validating the FileSystemStoragePathSource which monitors the file system for model versions and notifies targets of aspired versions.

Description

This test file provides comprehensive coverage of the FileSystemStoragePathSource class, which is a key component of the model serving pipeline responsible for discovering model versions on disk. The tests use a FileSystemStoragePathSourceTestAccess helper class to directly invoke file system polling and an aspired versions callback notifier. A MockStoragePathTarget is used to verify the correct aspired versions are communicated.

Key areas tested include:

  • No versions at startup (with and without base path, with fail_if_zero_versions flag)
  • Files appearing after startup
  • Multiple version discovery and version policy (latest, N latest, specific versions, all versions)
  • Leading zeros in version directories
  • Default version policy behavior
  • Multiple servable configuration
  • Dynamic configuration changes (servable set, version policy, polling period)
  • Timestamped version directory parsing
  • Servable version directory renaming
  • Duplicate version handling
  • Last version protection (not removed)
  • Single file system poll execution

Usage

Run these tests to validate changes to file system model discovery, version policy enforcement, or dynamic reconfiguration of storage path sources.

Code Reference

Source Location

  • Repository: Tensorflow_Serving
  • File: tensorflow_serving/sources/storage_path/file_system_storage_path_source_test.cc
  • Lines: 1-917

Test Fixture

class FileSystemStoragePathSourceTestAccess {
 public:
  explicit FileSystemStoragePathSourceTestAccess(Source<StoragePath>* source)
      : source_(static_cast<FileSystemStoragePathSource*>(source)) {}
  absl::Status PollFileSystemAndInvokeCallback() {
    return source_->PollFileSystemAndInvokeCallback();
  }
  void SetAspiredVersionsCallbackNotifier(std::function<void()> fn) {
    source_->SetAspiredVersionsCallbackNotifier(fn);
  }
};

// Tests use MockStoragePathTarget with StrictMock
std::unique_ptr<test_util::MockStoragePathTarget> target(
    new StrictMock<test_util::MockStoragePathTarget>);
ConnectSourceToTarget(source.get(), target.get());

Build Target

bazel test //tensorflow_serving/sources/storage_path:file_system_storage_path_source_test

Test Coverage

Key Test Cases

Test Name Category Description
NoVersionsAtStartup Startup Tests behavior with no versions at startup (with/without base path)
FilesAppearAfterStartup Discovery Tests discovering versions after initial empty poll
MultipleVersions Discovery Tests discovery of multiple version directories
MultipleVersionsAtTheSameTime Version Policy Tests all-versions policy with multiple versions
NLatestVersions Version Policy Tests N-latest versions policy
SpecificVersions Version Policy Tests specific version selection policy
SpecificVersionsLeadingZeros Version Policy Tests specific versions with leading zeros in directories
SpecificVersionsEmpty Version Policy Tests specific versions with empty version list
DefaultVersionPolicy Version Policy Tests default version policy behavior
DefaultNumLatestVersions Version Policy Tests default N for latest-N policy
MultipleServables Configuration Tests monitoring multiple servable base paths
ChangeSetOfServables Dynamic Config Tests dynamically changing the set of monitored servables
ChangeVersionPolicy Dynamic Config Tests dynamically changing version policy
AttemptToChangePollingPeriod Dynamic Config Tests that polling period cannot be changed
ParseTimestampedVersion Parsing Tests parsing timestamped version directory names
ServableVersionDirRenamed File System Tests handling of renamed version directories
DuplicateVersions Error Handling Tests handling of duplicate version numbers
LastVersionNotRemoved Protection Tests that last version is not removed from aspired list
PollFilesystemOnlyOnce Performance Tests single filesystem poll execution

Usage Examples

Test Pattern

TEST(FileSystemStoragePathSourceTest, FilesAppearAfterStartup) {
  const string base_path =
      io::JoinPath(testing::TmpDir(), "FilesAppearAfterStartup");

  auto config = test_util::CreateProto<FileSystemStoragePathSourceConfig>(...);
  std::unique_ptr<FileSystemStoragePathSource> source;
  TF_ASSERT_OK(FileSystemStoragePathSource::Create(config, &source));
  std::unique_ptr<test_util::MockStoragePathTarget> target(
      new StrictMock<test_util::MockStoragePathTarget>);
  ConnectSourceToTarget(source.get(), target.get());

  // Inject version directory and re-poll
  TF_ASSERT_OK(Env::Default()->CreateDir(io::JoinPath(base_path, "3")));
  EXPECT_CALL(*target, SetAspiredVersions(Eq("test_servable_name"),
      ElementsAre(ServableData<StoragePath>(
          {"test_servable_name", 3}, io::JoinPath(base_path, "3")))));
  TF_ASSERT_OK(internal::FileSystemStoragePathSourceTestAccess(source.get())
                   .PollFileSystemAndInvokeCallback());
}

Related Pages

Page Connections

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