Fix dict resize allow test (#13016)

Ci report this failure:
```
*** [err]: Don't rehash if used memory exceeds maxmemory after rehash in tests/unit/maxmemory.tcl
Expected '4098' to equal or match '4002'

WARNING: the new maxmemory value set via CONFIG SET (1176088) is smaller than the current memory usage (1231083)
```

It can be seen from the log that used_memory changed before we set
maxmemory.
The reason is that in #12819, in cron, in addition to trying to shrink,
we will
also tyring to expand. The dict was expanded by cron before we set
maxmemory,
causing the test to fail.

Before setting maxmemory, we only add 4095 keys to avoid triggering
resize.
This commit is contained in:
Binbin 2024-01-31 19:11:52 +08:00 committed by GitHub
parent 6016973ac0
commit 9a7d311855
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 1 deletions

View File

@ -421,11 +421,16 @@ start_server {tags {"maxmemory external:skip"}} {
r config set maxmemory-policy allkeys-random
# Next rehash size is 8192, that will eat 64k memory
populate 4096 "" 1
populate 4095 "" 1
set used [s used_memory]
set limit [expr {$used + 10*1024}]
r config set maxmemory $limit
# Adding a key to meet the 1:1 radio.
r set k0 v0
# The dict has reached 4096, it can be resized in tryResizeHashTables in cron,
# or we add a key to let it check whether it can be resized.
r set k1 v1
# Next writing command will trigger evicting some keys if last
# command trigger DB dict rehash