fix(dragonfly_test): failing bug207 on build opt (#1919)

The issue was that the Heartbeat would run every 1ms and this is problematic because the for-loop would take less than 1ms to finish. Therefore, the memory pool would not adjust and items would not be evicted from the store. By doubling the amount of elements created in the for-loop, we give enough time for the first heartbeat to run and adjust the memory available (which will cause the evictions to happen).
This commit is contained in:
Kostas Kyrimis 2023-09-25 11:02:53 +03:00 committed by GitHub
parent e30c6ce41d
commit 91e8ead6d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 4 deletions

View file

@ -152,7 +152,7 @@ bool PrimeEvictionPolicy::CanGrow(const PrimeTable& tbl) const {
if (!apply_memory_limit_ || mem_budget_ > soft_limit_)
return true;
DCHECK_LT(tbl.size(), tbl.capacity());
DCHECK_LE(tbl.size(), tbl.capacity());
// We take a conservative stance here -
// we estimate how much memory we will take with the current capacity

View file

@ -382,16 +382,15 @@ TEST_F(DflyEngineTest, OOM) {
/// Reproduces the case where items with expiry data were evicted,
/// and then written with the same key.
TEST_F(DflyEngineTest, Bug207) {
max_memory_limit = 300000;
shard_set->TEST_EnableHeartBeat();
shard_set->TEST_EnableCacheMode();
absl::FlagSaver fs;
absl::SetFlag(&FLAGS_oom_deny_ratio, 4);
max_memory_limit = 300000;
ssize_t i = 0;
RespExpr resp;
for (; i < 5000; ++i) {
for (; i < 10000; ++i) {
resp = Run({"setex", StrCat("key", i), "30", "bar"});
// we evict some items because 5000 is too much when max_memory_limit is 300000.
ASSERT_EQ(resp, "OK");