diff options
author | Binbin <binloveplay1314@qq.com> | 2023-03-21 23:51:47 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-21 17:51:47 +0200 |
commit | 78f15b7ef1a00e5c83d7128cefaf02f9262b9452 (patch) | |
tree | 272a2bb2fea6f15637a8a11e17afea5c4cbae4e4 /tests | |
parent | 1cb4b1ad07a0c9a0d256a4b947158ae6658458d2 (diff) | |
download | redis-78f15b7ef1a00e5c83d7128cefaf02f9262b9452.tar.gz |
Fix race in temp rdb delete shutdown test (#11840)
I saw this error once, in the FreeBSD Daily CI:
```
*** [err]: Temp rdb will be deleted if we use bg_unlink when shutdown in tests/unit/shutdown.tcl
Expected [file exists /xxx/temp-10336.rdb] (context: type eval line 15 cmd {assert {[file exists $temp_rdb]}} proc ::test)
```
The log shows that bgsave was executed, and it was successfully executed in the end:
```
Starting test Temp rdb will be deleted if we use bg_unlink when shutdown in tests/unit/shutdown.tcl
10251:M 22 Feb 2023 11:37:25.441 * Background saving started by pid 10336
10336:C 22 Feb 2023 11:37:27.949 * DB saved on disk
10336:C 22 Feb 2023 11:37:27.949 * Fork CoW for RDB: current 0 MB, peak 0 MB, average 0 MB
10251:M 22 Feb 2023 11:37:28.060 * Background saving terminated with success
```
There may be two reasons:
1. The child process has been created, but it has not created
the temp rdb file yet, so [file exists $temp_rdb] check failed.
2. The child process bgsave has been executed successfully and the
temp file has been deleted, so [file exists $temp_rdb] check failed.
From the logs pint, it should be the case 2, case 1 is too extreme,
set rdb-key-save-delay to a higher value to ensure bgsave does not
succeed early to avoid this case.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/shutdown.tcl | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/tests/unit/shutdown.tcl b/tests/unit/shutdown.tcl index d0a8ffb6d..b419c83a1 100644 --- a/tests/unit/shutdown.tcl +++ b/tests/unit/shutdown.tcl @@ -3,12 +3,17 @@ start_server {tags {"shutdown external:skip"}} { for {set i 0} {$i < 20} {incr i} { r set $i $i } - # It will cost 2s(20 * 100ms) to dump rdb - r config set rdb-key-save-delay 100000 + r config set rdb-key-save-delay 10000000 # Child is dumping rdb r bgsave - after 100 + wait_for_condition 1000 10 { + [s rdb_bgsave_in_progress] eq 1 + } else { + fail "bgsave did not start in time" + } + after 100 ;# give the child a bit of time for the file to be created + set dir [lindex [r config get dir] 1] set child_pid [get_child_pid 0] set temp_rdb [file join [lindex [r config get dir] 1] temp-${child_pid}.rdb] |