ignores reporting cancellations as errors in the usage-reporter module (#6058)

pull/5943/head^2
Owen Diehl 3 years ago committed by GitHub
parent 9cb78bdad8
commit 309592a8cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      pkg/usagestats/reporter.go
  2. 4
      pkg/usagestats/reporter_test.go

@ -3,6 +3,7 @@ package usagestats
import (
"bytes"
"context"
"errors"
"flag"
"io"
"math"
@ -254,7 +255,10 @@ func (rep *Reporter) running(ctx context.Context) error {
if rep.cluster == nil {
<-ctx.Done()
return ctx.Err()
if err := ctx.Err(); !errors.Is(err, context.Canceled) {
return err
}
return nil
}
// check every minute if we should report.
ticker := time.NewTicker(reportCheckInterval)
@ -281,7 +285,10 @@ func (rep *Reporter) running(ctx context.Context) error {
rep.lastReport = next
next = next.Add(reportInterval)
case <-ctx.Done():
return ctx.Err()
if err := ctx.Err(); !errors.Is(err, context.Canceled) {
return err
}
return nil
}
}
}

@ -97,7 +97,7 @@ func Test_ReportLoop(t *testing.T) {
<-time.After(6*time.Second + (stabilityCheckInterval * time.Duration(stabilityMinimunRequired+1)))
cancel()
}()
require.Equal(t, context.Canceled, r.running(ctx))
require.Equal(t, nil, r.running(ctx))
require.GreaterOrEqual(t, totalReport, 5)
first := clusterIDs[0]
for _, uid := range clusterIDs {
@ -156,5 +156,5 @@ func TestWrongKV(t *testing.T) {
<-time.After(1 * time.Second)
cancel()
}()
require.Equal(t, context.Canceled, r.running(ctx))
require.Equal(t, nil, r.running(ctx))
}

Loading…
Cancel
Save