From 45192d21043864becf9c88705b560138f663378e Mon Sep 17 00:00:00 2001 From: Dirkjan Bussink Date: Thu, 12 Dec 2024 22:23:58 +0100 Subject: [PATCH] Fix flaky mysqlctl blackbox test (#17387) --- go/vt/logutil/logger.go | 7 +++++++ go/vt/mysqlctl/blackbox/utils.go | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/go/vt/logutil/logger.go b/go/vt/logutil/logger.go index 47c3f124238..46d7c0052da 100644 --- a/go/vt/logutil/logger.go +++ b/go/vt/logutil/logger.go @@ -20,6 +20,7 @@ import ( "fmt" "io" "runtime" + "slices" "strings" "sync" "time" @@ -246,6 +247,12 @@ func (ml *MemoryLogger) Clear() { ml.mu.Unlock() } +func (ml *MemoryLogger) LogEvents() []*logutilpb.Event { + ml.mu.Lock() + defer ml.mu.Unlock() + return slices.Clone(ml.Events) +} + // LoggerWriter is an adapter that implements the io.Writer interface. type LoggerWriter struct { logger Logger diff --git a/go/vt/mysqlctl/blackbox/utils.go b/go/vt/mysqlctl/blackbox/utils.go index e4e3f11fb3c..c7d34ae3cf6 100644 --- a/go/vt/mysqlctl/blackbox/utils.go +++ b/go/vt/mysqlctl/blackbox/utils.go @@ -78,7 +78,7 @@ func GetStats(stats *backupstats.FakeStats) StatSummary { func AssertLogs(t *testing.T, expectedLogs []string, logger *logutil.MemoryLogger) { for _, log := range expectedLogs { - require.Truef(t, slices.ContainsFunc(logger.Events, func(event *logutilpb.Event) bool { + require.Truef(t, slices.ContainsFunc(logger.LogEvents(), func(event *logutilpb.Event) bool { return event.GetValue() == log }), "%s is missing from the logs", log) }