Skip to content

Commit 2b806ee

Browse files
author
Liam Merino
committed
Fix flaky zstd compression-level test
The test compared output sizes for levels 1 vs 10 on a 20KB pcap; on inputs that small, zstd produces identical output for both levels, so the GREATER_THAN assertion always failed. Switch to a larger input (EXAMPLE2_PCAPNG_PATH, ~26KB) and widen the gap to levels 1 vs 22 (zstd's documented max), which produces a clear size delta. Also brace the single-statement while body per review nit.
1 parent ff4ae21 commit 2b806ee

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

Tests/Pcap++Test/Tests/FileTests.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,26 +1317,32 @@ PTF_TEST_CASE(TestPcapNgFileReadWrite)
13171317
PTF_TEST_CASE(TestPcapNgZstdCompressionLevels)
13181318
{
13191319
// If the compression level is silently ignored, low and high levels
1320-
// produce identical output sizes.
1321-
int sizes[2] = { 0, 0 };
1322-
const int levels[2] = { 1, 10 };
1323-
for (int i = 0; i < 2; i++)
1324-
{
1325-
pcpp::PcapNgFileReaderDevice readerDev(EXAMPLE_PCAPNG_PATH);
1320+
// produce identical output sizes. PcapPlusPlus exposes levels 0-10,
1321+
// which the zstd wrapper maps to zstd's native 1-22 range. Test three
1322+
// points to verify the level scales monotonically, not just that the
1323+
// endpoints differ.
1324+
int sizes[3] = { 0, 0, 0 };
1325+
const int levels[3] = { 1, 5, 10 };
1326+
for (int i = 0; i < 3; i++)
1327+
{
1328+
pcpp::PcapNgFileReaderDevice readerDev(EXAMPLE2_PCAPNG_PATH);
13261329
PTF_ASSERT_TRUE(readerDev.open());
13271330

13281331
pcpp::PcapNgFileWriterDevice writerDev(EXAMPLE_PCAPNG_ZSTD_LEVELS_WRITE_PATH, levels[i]);
13291332
PTF_ASSERT_TRUE(writerDev.open());
13301333

13311334
pcpp::RawPacket rawPacket;
13321335
while (readerDev.getNextPacket(rawPacket))
1336+
{
13331337
PTF_ASSERT_TRUE(writerDev.writePacket(rawPacket));
1338+
}
13341339
readerDev.close();
13351340
writerDev.close();
13361341

13371342
sizes[i] = getFileLength(EXAMPLE_PCAPNG_ZSTD_LEVELS_WRITE_PATH);
13381343
}
13391344
PTF_ASSERT_GREATER_THAN(sizes[0], sizes[1]);
1345+
PTF_ASSERT_GREATER_THAN(sizes[1], sizes[2]);
13401346
} // TestPcapNgZstdCompressionLevels
13411347

13421348
PTF_TEST_CASE(TestPcapNgFileReadWriteAdv)

0 commit comments

Comments
 (0)