Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(tests): refactor and enhance test cases to prevent flaky test failure #2544

Open
wants to merge 1 commit into
base: unstable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 31 additions & 32 deletions tests/gocase/unit/log/logclean_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,40 +29,39 @@ import (
)

func TestLogClean(t *testing.T) {
err := os.Mkdir("/tmp/kvrocks/logfile", os.ModePerm)
if err != nil {
return
}
srv1 := util.StartServer(t, map[string]string{
"log-dir": "/tmp/kvrocks/logfile",
"log-retention-days": "0",
})
srv1.Close()
files1, _ := os.ReadDir("/tmp/kvrocks/logfile")
time.Sleep(2000 * time.Millisecond)
srv2 := util.StartServer(t, map[string]string{
"log-dir": "/tmp/kvrocks/logfile",
logDir := "/tmp/kvrocks/logfile"
require.NoError(t, os.RemoveAll(logDir))
require.NoError(t, os.MkdirAll(logDir, os.ModePerm))

srv := util.StartServer(t, map[string]string{
"log-dir": logDir,
"log-retention-days": "0",
})
srv2.Close()
files2, _ := os.ReadDir("/tmp/kvrocks/logfile")
islogclear := false
for _, f1 := range files1 {
ishave := false
for _, f2 := range files2 {
if f1.Name() == f2.Name() {
ishave = true
break
}
}
if !ishave {
islogclear = true
break
}
}
require.Equal(t, true, islogclear)
err = os.RemoveAll("/tmp/kvrocks/logfile")
if err != nil {
defer srv.Close()

files1, err := os.ReadDir(logDir)
require.NoError(t, err)
if len(files1) == 0 {
return
}
require.Eventually(t, func() bool {
srv.Restart()

files2, err := os.ReadDir(logDir)
require.NoError(t, err)
for _, f1 := range files1 {
fileExists := false
for _, f2 := range files2 {
if f1.Name() == f2.Name() {
fileExists = true
break
}
}
// If the file does not exist, it means the file has been cleaned
if !fileExists {
return true
}
}
return false
}, 10*time.Second, 200*time.Millisecond)
}
13 changes: 9 additions & 4 deletions utils/kvrocks2redis/tests/check_consistency.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,17 @@ def _import_and_compare(self, num):
time.sleep(0.02)
keys = [key, incr_key, hash_key, set_key, zset_key]
for key in keys:
data_type = self.src_cli.type(key)
src_data, dst_data = self._compare_data([key], data_type)
if src_data != dst_data:
attempts = 0
while attempts <= 3:
data_type = self.src_cli.type(key)
src_data, dst_data = self._compare_data([key], data_type)
if src_data == dst_data:
break
attempts += 1
time.sleep(0.1)
else:
raise AssertionError(f"Data mismatch for key '{key}': source data: '{src_data}' destination data: '{dst_data}'")


if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Redis Comparator')
parser.add_argument('--src_host', type=str, default='127.0.0.1', help='Source Redis host')
Expand Down
Loading