pkg/audit: fix maxRetries bug (#2271)

This commit is contained in:
Natalie Villasana 2019-06-21 11:10:03 -04:00 committed by GitHub
parent 86ec9b9570
commit 169fc9594c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 4 deletions

View File

@ -65,8 +65,8 @@ func (reporter *Reporter) RecordAudits(ctx context.Context, req *Report) (failed
var errlist errs.Group
retries := 0
for retries < reporter.maxRetries {
tries := 0
for tries <= reporter.maxRetries {
if len(successes) == 0 && len(fails) == 0 && len(offlines) == 0 && len(pendingAudits) == 0 {
return nil, nil
}
@ -98,11 +98,11 @@ func (reporter *Reporter) RecordAudits(ctx context.Context, req *Report) (failed
}
}
retries++
tries++
}
err = errlist.Err()
if retries >= reporter.maxRetries && err != nil {
if tries >= reporter.maxRetries && err != nil {
return &Report{
Successes: successes,
Fails: fails,

View File

@ -53,3 +53,30 @@ func TestReportPendingAudits(t *testing.T) {
assert.Equal(t, pending, *pa)
})
}
func TestRecordAuditsAtLeastOnce(t *testing.T) {
testplanet.Run(t, testplanet.Config{
SatelliteCount: 1, StorageNodeCount: 1, UplinkCount: 0,
}, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet) {
err := planet.Satellites[0].Audit.Service.Close()
require.NoError(t, err)
nodeID := planet.StorageNodes[0].ID()
report := audit.Report{Successes: []storj.NodeID{nodeID}}
overlay := planet.Satellites[0].Overlay.Service
containment := planet.Satellites[0].DB.Containment()
// set maxRetries to 0
reporter := audit.NewReporter(zap.L(), overlay, containment, 0, 3)
// expect RecordAudits to try recording at least once
failed, err := reporter.RecordAudits(ctx, &report)
require.NoError(t, err)
require.Zero(t, failed)
node, err := overlay.Get(ctx, nodeID)
require.NoError(t, err)
require.EqualValues(t, 1, node.Reputation.AuditCount)
})
}