From 8f225673a2e4a848f57fafa02dad6afdd1c4ae39 Mon Sep 17 00:00:00 2001 From: Ti Chi Robot Date: Fri, 27 Dec 2024 11:08:10 +0800 Subject: [PATCH] redo(ticdc): Fix RedoLogWriter unit test (#11853) (#11940) close pingcap/tiflow#11852 --- cdc/redo/writer/memory/mem_log_writer_test.go | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/cdc/redo/writer/memory/mem_log_writer_test.go b/cdc/redo/writer/memory/mem_log_writer_test.go index b72b106e92b..e8a21aea4bb 100644 --- a/cdc/redo/writer/memory/mem_log_writer_test.go +++ b/cdc/redo/writer/memory/mem_log_writer_test.go @@ -101,12 +101,30 @@ func testWriteEvents(t *testing.T, events []writer.RedoEvent) { functions := map[string]func(error){ "WriteEvents": func(expected error) { - err := lw.WriteEvents(ctx, events...) - require.ErrorIs(t, errors.Cause(err), expected) + if expected == nil { + err := lw.WriteEvents(ctx, events...) + require.NoError(t, err) + } else { + require.Eventually( + t, func() bool { + err := lw.WriteEvents(ctx, events...) + return errors.Is(errors.Cause(err), expected) + }, time.Second*2, time.Microsecond*10, + ) + } }, "FlushLog": func(expected error) { - err := lw.FlushLog(ctx) - require.ErrorIs(t, errors.Cause(err), expected) + if expected == nil { + err := lw.FlushLog(ctx) + require.NoError(t, err) + } else { + require.Eventually( + t, func() bool { + err := lw.WriteEvents(ctx, events...) + return errors.Is(errors.Cause(err), expected) + }, time.Second*2, time.Microsecond*10, + ) + } }, } firstCall := true