Implementation:Tensorflow Serving Evhttp Request Test
| Knowledge Sources | |
|---|---|
| Domains | Testing, HTTP, Networking |
| Last Updated | 2026-02-13 00:00 GMT |
Overview
Test suite validating the evhttp-based HTTP request handling, including GET, POST, headers, URI parsing, and gzip compression support.
Description
This test file validates the HTTP request handling functionality of the evhttp-based server implementation. The EvHTTPRequestTest fixture creates an HTTP server with a FixedThreadPool-backed executor, registers request handlers, and uses TestEvHTTPConnection to send requests and verify responses. Tests cover the full request/response lifecycle including method handling, header processing, URI parsing, and gzip content encoding.
Key areas tested include:
- Basic GET request with 404 (no handler) and 200 (with handler)
- POST request with echo body
- Request URI and query parameter parsing
- Request header reading
- Response header writing
- Gzip POST handling: invalid gzip, disabled gzip, valid gzip, gzip exceeding limit
- Large gzip POST handling
Usage
Run these tests to validate changes to the HTTP request handler, header processing, or gzip compression support in the evhttp server.
Code Reference
Source Location
- Repository: Tensorflow_Serving
- File: tensorflow_serving/util/net_http/server/internal/evhttp_request_test.cc
- Lines: 1-462
Test Fixture
class MyExecutor final : public EventExecutor {
public:
explicit MyExecutor(int num_threads) : thread_pool_(num_threads) {}
void Schedule(std::function<void()> fn) override {
thread_pool_.Schedule(fn);
}
private:
FixedThreadPool thread_pool_;
};
class EvHTTPRequestTest : public ::testing::Test {
public:
void SetUp() override { InitServer(); }
void TearDown() override {
if (!server->is_terminating()) {
server->Terminate();
server->WaitForTermination();
}
}
protected:
std::unique_ptr<HTTPServerInterface> server;
};
Build Target
bazel test //tensorflow_serving/util/net_http/server/internal:evhttp_request_test
Test Coverage
Key Test Cases
| Test Name | Category | Description |
|---|---|---|
| SimpleGETNotFound | HTTP Method | Tests GET request returning 404 when no handler registered |
| SimpleGETOK | HTTP Method | Tests GET request returning 200 with registered handler |
| SimplePOST | HTTP Method | Tests POST request with body echo |
| RequestUri | URI Parsing | Tests request URI and query parameter access |
| RequestHeaders | Headers | Tests reading request headers |
| ResponseHeaders | Headers | Tests writing response headers |
| InvalidGzipPost | Compression | Tests rejection of invalid gzip content |
| DisableGzipPost | Compression | Tests disabled gzip decompression |
| ValidGzipPost | Compression | Tests valid gzip-compressed POST body |
| GzipExceedingLimit | Compression | Tests gzip exceeding decompression size limit |
| LargeGzipPost | Compression | Tests large gzip-compressed POST body |
Usage Examples
Test Pattern
TEST_F(EvHTTPRequestTest, SimpleGETOK) {
auto handler = [](ServerRequestInterface* request) {
request->WriteResponseString("OK");
request->Reply();
};
server->RegisterRequestHandler("/ok", std::move(handler),
RequestHandlerOptions());
server->StartAcceptingRequests();
auto connection =
TestEvHTTPConnection::Connect("localhost", server->listen_port());
ASSERT_TRUE(connection != nullptr);
TestClientRequest request = {"/ok", "GET", {}, ""};
TestClientResponse response = {};
EXPECT_TRUE(connection->BlockingSendRequest(request, &response));
EXPECT_EQ(response.status, HTTPStatusCode::OK);
EXPECT_EQ(response.body, "OK");
}