pkg/audit: fix maxRetries bug (#2271)
This commit is contained in:
parent
86ec9b9570
commit
169fc9594c
@ -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,
|
||||
|
@ -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)
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user