Implementation:Tensorflow Serving Gzip Zlib Test
| Knowledge Sources | |
|---|---|
| Domains | Testing, Compression, HTTP |
| Last Updated | 2026-02-13 00:00 GMT |
Overview
Test suite validating the gzip/zlib compression and decompression utilities used by the HTTP server.
Description
This test file validates the GZipHeader parser and ZLib compression/decompression classes in the net_http compression library. The GzipHeader.FragmentTest uses randomized fragmentation to test robust parsing of gzip headers with various optional fields (FNAME, FCOMMENT, FHCRC, extra data). The ZLibTest suite covers a range of compression and decompression scenarios.
Key areas tested include:
- Gzip header parsing with randomized fragmentation across many header variants
- Huge data compression (stress test)
- Standard compression and decompression round-trip
- Error handling for corrupt data
- Chunked header decompression
- Gzip-specific compression mode
- Chunked compression and decompression
- Byte-wise reading of compressed data
- Truncated data handling
- Gzip uncompressed length extraction
Usage
Run these tests to validate changes to the compression library used by the HTTP server for request/response body compression.
Code Reference
Source Location
- Repository: Tensorflow_Serving
- File: tensorflow_serving/util/net_http/compression/gzip_zlib_test.cc
- Lines: 1-702
Test Fixture
// GzipHeader FragmentTest uses randomized fragmentation
TEST(GzipHeader, FragmentTest) {
RandomEngine rng(rd());
struct TestCase {
const char* str;
int len;
int cruft_len;
};
TestCase tests[] = {
{"\037\213\010\000...", 10, 0}, // Basic header
// ... many variants with FNAME, FCOMMENT, FHCRC, extras
};
for (auto test : tests) {
for (int j = 0; j < 1000; ++j) {
// Random fragmentation of header bytes
GZipHeader gzip_headers;
// Parse fragments until complete
}
}
}
Build Target
bazel test //tensorflow_serving/util/net_http/compression:gzip_zlib_test
Test Coverage
Key Test Cases
| Test Name | Category | Description |
|---|---|---|
| GzipHeader.FragmentTest | Parsing | Tests gzip header parsing with randomized fragmentation |
| ZLibTest.HugeCompression | Stress | Tests compression of large data blocks |
| ZLibTest.Compression | Round Trip | Tests standard compress/decompress round-trip |
| ZLibTest.OtherErrors | Error Handling | Tests error handling for corrupt compressed data |
| ZLibTest.UncompressChunkedHeaders | Decompression | Tests decompression with chunked gzip headers |
| ZLibTest.GzipCompression | Format | Tests gzip-specific compression mode |
| ZLibTest.ChunkedCompression | Streaming | Tests chunked compression and decompression |
| ZLibTest.BytewiseRead | Streaming | Tests byte-by-byte reading of compressed data |
| ZLibTest.TruncatedData | Error Handling | Tests handling of truncated compressed data |
| ZLibTest.GzipUncompressedLength | Metadata | Tests extraction of gzip uncompressed length |
Usage Examples
Test Pattern
TEST(ZLibTest, Compression) {
// Compress data
string compressed;
ZLib zlib;
zlib.Compress(input_data, input_len, &compressed);
// Decompress and verify
string decompressed;
zlib.Uncompress(compressed.data(), compressed.size(), &decompressed);
EXPECT_EQ(input_data, decompressed);
}