Add QpackHeaderTable::draining_index().
gfe-relnote: n/a, change to QUIC v99-only code. Protected by existing disabled
gfe2_reloadable_flag_quic_enable_version_99.
PiperOrigin-RevId: 259954990
Change-Id: I896a5b039f2d61e7b4e9f97299b9ebb2234e2820
diff --git a/quic/core/qpack/qpack_header_table_test.cc b/quic/core/qpack/qpack_header_table_test.cc
index ff7ef48..7d1044b 100644
--- a/quic/core/qpack/qpack_header_table_test.cc
+++ b/quic/core/qpack/qpack_header_table_test.cc
@@ -404,6 +404,42 @@
Mock::VerifyAndClearExpectations(&observer5);
}
+TEST_F(QpackHeaderTableTest, DrainingIndex) {
+ QpackHeaderTable table;
+ table.SetMaximumDynamicTableCapacity(4 * QpackEntry::Size("foo", "bar"));
+
+ // Empty table: no draining entry.
+ EXPECT_EQ(0u, table.draining_index(0.0));
+ EXPECT_EQ(0u, table.draining_index(1.0));
+
+ // Table with one entry.
+ EXPECT_TRUE(table.InsertEntry("foo", "bar"));
+ // Any entry can be referenced if none of the table is draining.
+ EXPECT_EQ(0u, table.draining_index(0.0));
+ // No entry can be referenced if all of the table is draining.
+ EXPECT_EQ(1u, table.draining_index(1.0));
+
+ // Table with two entries is at half capacity.
+ EXPECT_TRUE(table.InsertEntry("foo", "bar"));
+ // Any entry can be referenced if at most half of the table is draining,
+ // because current entries only take up half of total capacity.
+ EXPECT_EQ(0u, table.draining_index(0.0));
+ EXPECT_EQ(0u, table.draining_index(0.5));
+ // No entry can be referenced if all of the table is draining.
+ EXPECT_EQ(2u, table.draining_index(1.0));
+
+ // Table with four entries is full.
+ EXPECT_TRUE(table.InsertEntry("foo", "bar"));
+ EXPECT_TRUE(table.InsertEntry("foo", "bar"));
+ // Any entry can be referenced if none of the table is draining.
+ EXPECT_EQ(0u, table.draining_index(0.0));
+ // In a full table with identically sized entries, |draining_fraction| of all
+ // entries are draining.
+ EXPECT_EQ(2u, table.draining_index(0.5));
+ // No entry can be referenced if all of the table is draining.
+ EXPECT_EQ(4u, table.draining_index(1.0));
+}
+
} // namespace
} // namespace test
} // namespace quic