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 Evhttp Server Test

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

Overview

Test suite validating the evhttp-based HTTP server lifecycle, routing, request dispatching, and shutdown behavior.

Description

This test file validates the HTTP server implementation built on libevent's evhttp. The EvHTTPServerTest fixture creates a server with a FixedThreadPool-backed executor and tests server lifecycle (start, accept, terminate), path-based routing, request handler overwriting, request dispatchers (single and ordered), handler interaction patterns, and active request counting during shutdown.

A separate EvHTTPServerTestWithAddress fixture tests address-specific binding and basic listen functionality.

Key areas tested include:

  • Server accepting and termination lifecycle
  • Exact path matching (including trailing slash handling)
  • Request handler overwriting
  • Single request dispatcher (fallback handler)
  • URI handler precedence over request dispatcher
  • In-order request dispatcher chain
  • Request handler interaction patterns
  • Active request count tracking during shutdown
  • Address-specific listen binding

Usage

Run these tests to validate changes to the HTTP server lifecycle, routing logic, request dispatching, or shutdown behavior.

Code Reference

Source Location

  • Repository: Tensorflow_Serving
  • File: tensorflow_serving/util/net_http/server/internal/evhttp_server_test.cc
  • Lines: 1-367

Test Fixture

class EvHTTPServerTest : public ::testing::Test {
 public:
  void SetUp() override { InitServer(); }
  void TearDown() override {
    if (!server->is_terminating()) {
      server->Terminate();
      server->WaitForTermination();
    }
  }
 protected:
  virtual std::unique_ptr<ServerOptions> GetOptions() {
    auto options = absl::make_unique<ServerOptions>();
    options->AddPort(0);
    options->SetExecutor(absl::make_unique<MyExecutor>(4));
    return options;
  }
  std::unique_ptr<HTTPServerInterface> server;
};

Build Target

bazel test //tensorflow_serving/util/net_http/server/internal:evhttp_server_test

Test Coverage

Key Test Cases

Test Name Category Description
AcceptingTerminating Lifecycle Tests server start accepting and graceful termination
ExactPathMatching Routing Tests exact path matching with query params and trailing slash
RequestHandlerOverwriting Routing Tests that new handler replaces old handler for same path
SingleRequestDispather Dispatching Tests single fallback request dispatcher
UriPrecedesOverRequestDispather Dispatching Tests URI handler takes precedence over dispatcher
InOrderRequestDispather Dispatching Tests ordered chain of request dispatchers
RequestHandlerInteraction Integration Tests interaction between handlers and dispatchers
ActiveRequestCountInShutdown Shutdown Tests active request counting during server shutdown
EvHTTPServerTestWithAddress.BasicListen Binding Tests address-specific listen binding

Usage Examples

Test Pattern

TEST_F(EvHTTPServerTest, AcceptingTerminating) {
  EXPECT_FALSE(server->is_accepting_requests());
  server->StartAcceptingRequests();
  EXPECT_TRUE(server->is_accepting_requests());

  server->Terminate();
  EXPECT_TRUE(server->is_terminating());

  server->WaitForTermination();
}

Related Pages

Page Connections

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