From a407ad529adcdf997eb523cb13249e584948911b Mon Sep 17 00:00:00 2001 From: Artem Gavrilov Date: Tue, 26 Sep 2023 16:05:44 +0200 Subject: [PATCH] PMM-7 Fix datarace (#2501) * PMM-7 Fix datarace * PMM-7 Fix datarace --- managed/services/telemetry/telemetry.go | 6 +++--- managed/services/telemetry/telemetry_test.go | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/managed/services/telemetry/telemetry.go b/managed/services/telemetry/telemetry.go index 81f2450215..867f31f211 100644 --- a/managed/services/telemetry/telemetry.go +++ b/managed/services/telemetry/telemetry.go @@ -188,8 +188,8 @@ func (s *Service) processSendCh(ctx context.Context) { reportsBuf = []*pmmv1.ServerMetric{} reportsBufSync.Unlock() - go func() { - err := s.send(sendCtx, &reporter.ReportRequest{ + go func(ctx context.Context) { + err := s.send(ctx, &reporter.ReportRequest{ Metrics: reportsToSend, }) if err != nil { @@ -201,7 +201,7 @@ func (s *Service) processSendCh(ctx context.Context) { } s.l.Debug("Telemetry info sent.") - }() + }(sendCtx) } case <-ctx.Done(): if cancel != nil { diff --git a/managed/services/telemetry/telemetry_test.go b/managed/services/telemetry/telemetry_test.go index 842b6e9233..726e80cbaa 100644 --- a/managed/services/telemetry/telemetry_test.go +++ b/managed/services/telemetry/telemetry_test.go @@ -19,7 +19,6 @@ import ( "context" "io/fs" "os" - "reflect" "testing" "time" @@ -264,7 +263,7 @@ func initMockTelemetrySender(t *testing.T, expectedReport *reporter.ReportReques var mockTelemetrySender mockSender mockTelemetrySender.Test(t) mockTelemetrySender.On("SendTelemetry", - mock.AnythingOfType(reflect.TypeOf(context.TODO()).Name()), + mock.Anything, mock.MatchedBy(func(report *reporter.ReportRequest) bool { return matchExpectedReport(report, expectedReport) }),