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..71b8b6b792f 100644 --- a/utils/kvrocks2redis/tests/check_consistency.py +++ b/utils/kvrocks2redis/tests/check_consistency.py @@ -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')