diff --git a/tests/gocase/unit/log/logclean_test.go b/tests/gocase/unit/log/logclean_test.go index df3dbc36944..b3d6ac80d52 100644 --- a/tests/gocase/unit/log/logclean_test.go +++ b/tests/gocase/unit/log/logclean_test.go @@ -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) } diff --git a/utils/kvrocks2redis/tests/check_consistency.py b/utils/kvrocks2redis/tests/check_consistency.py index 72477978120..4d6216ded10 100644 --- a/utils/kvrocks2redis/tests/check_consistency.py +++ b/utils/kvrocks2redis/tests/check_consistency.py @@ -112,8 +112,13 @@ def _import_and_compare(self, num): for key in keys: data_type = self.src_cli.type(key) src_data, dst_data = self._compare_data([key], data_type) + + attempts = 0 if src_data != dst_data: - raise AssertionError(f"Data mismatch for key '{key}': source data: '{src_data}' destination data: '{dst_data}'") + if attempts >= 3: + raise AssertionError(f"Data mismatch for key '{key}': source data: '{src_data}' destination data: '{dst_data}'") + attempts += 1 + time.sleep(0.1) if __name__ == '__main__':